Weglot Translate – Translate your WP website - Version 2.1.0

Version Description

(25/09/2018) = * New feature: Custom URL * Bugfix : Translate AJAX with return JSON on error * Bugfix : Backslash on function PHP * Bugfix : Replace links href on JSON translate * Bugfix : Compatibility with theme use ob_start

Download this release

Release Info

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

Code changes from version 2.0.7 to 2.1.0

Files changed (48) hide show
  1. app/javascripts/index.js +7 -7
  2. app/javascripts/metaboxes.js +5 -0
  3. app/javascripts/metaboxes/url-translate.js +105 -0
  4. app/javascripts/{admin-button-preview.js → settings/admin-button-preview.js} +0 -0
  5. app/javascripts/{admin-change-country.js → settings/admin-change-country.js} +0 -0
  6. app/javascripts/{admin-check-api-key.js → settings/admin-check-api-key.js} +0 -0
  7. app/javascripts/{admin-exclusion.js → settings/admin-exclusion.js} +0 -0
  8. app/javascripts/{admin-prevent-save-form.js → settings/admin-prevent-save-form.js} +0 -0
  9. app/javascripts/{admin-select.js → settings/admin-select.js} +20 -1
  10. app/javascripts/{admin-weglot-box.js → settings/admin-weglot-box.js} +0 -0
  11. app/styles/admin.scss +24 -0
  12. bootstrap.php +1 -0
  13. dist/admin-css.js +1 -1
  14. dist/admin-js.js +1 -1
  15. dist/css/admin-css.css +18 -0
  16. dist/front-amp-css.js +1 -1
  17. dist/front-css.js +1 -1
  18. dist/front-js.js +1 -1
  19. dist/metaboxes-js.js +1 -0
  20. readme.txt +9 -2
  21. src/actions/admin/class-admin-enqueue-weglot.php +16 -0
  22. src/actions/admin/class-metabox-url-translate-weglot.php +284 -0
  23. src/actions/front/class-translate-page-weglot.php +133 -16
  24. src/helpers/class-helper-json-inline-weglot.php +2 -2
  25. src/helpers/class-helper-post-meta-weglot.php +19 -0
  26. src/services/class-button-service-weglot.php +31 -5
  27. src/services/class-option-service-weglot.php +2 -0
  28. src/services/class-replace-link-service-weglot.php +14 -1
  29. src/services/class-replace-url-service-weglot.php +1 -1
  30. src/services/class-request-url-service-weglot.php +16 -2
  31. src/services/class-user-api-service-weglot.php +6 -6
  32. src/third/woocommerce/class-wc-translate-weglot.php +8 -0
  33. templates/admin/metaboxes/url-translate.php +67 -0
  34. templates/admin/pages/tabs/status.php +9 -2
  35. vendor/autoload.php +1 -1
  36. vendor/composer/autoload_real.php +7 -7
  37. vendor/composer/autoload_static.php +4 -4
  38. vendor/composer/installed.json +6 -6
  39. vendor/weglot/weglot-php/CHANGELOG.md +3 -0
  40. vendor/weglot/weglot-php/src/Parser/Check/Dom/AbstractDomChecker.php +7 -0
  41. vendor/weglot/weglot-php/src/Parser/Check/Dom/ImageAlt.php +5 -0
  42. vendor/weglot/weglot-php/src/Parser/Check/Dom/LinkDataTitle.php +5 -0
  43. vendor/weglot/weglot-php/src/Parser/Check/Dom/LinkTitle.php +5 -0
  44. vendor/weglot/weglot-php/src/Parser/Check/Dom/MetaContent.php +5 -0
  45. vendor/weglot/weglot-php/src/Parser/Formatter/DomFormatter.php +1 -1
  46. webpack.config.js +2 -1
  47. weglot-functions.php +1 -1
  48. weglot.php +4 -3
app/javascripts/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import InitAdminSelect from './admin-select'
2
- import InitAdminWeglotBox from './admin-weglot-box'
3
- import InitAdminExclusion from './admin-exclusion'
4
- import InitAdminButtonPreview from './admin-button-preview'
5
- import InitAdminCheckApiKey from './admin-check-api-key'
6
- import InitAdminChangeCountry from './admin-change-country'
7
- import InitAdminPreventSaveForm from './admin-prevent-save-form'
8
  import './find-polyfill'
9
  import './filter-polyfill'
10
 
1
+ import InitAdminSelect from './settings/admin-select'
2
+ import InitAdminWeglotBox from './settings/admin-weglot-box'
3
+ import InitAdminExclusion from './settings/admin-exclusion'
4
+ import InitAdminButtonPreview from './settings/admin-button-preview'
5
+ import InitAdminCheckApiKey from './settings/admin-check-api-key'
6
+ import InitAdminChangeCountry from './settings/admin-change-country'
7
+ import InitAdminPreventSaveForm from './settings/admin-prevent-save-form'
8
  import './find-polyfill'
9
  import './filter-polyfill'
10
 
app/javascripts/metaboxes.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ import "./find-polyfill";
2
+ import "./filter-polyfill";
3
+ import InitUrlTranslate from "./metaboxes/url-translate";
4
+
5
+ InitUrlTranslate();
app/javascripts/metaboxes/url-translate.js ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import slugify from 'slugify'
2
+
3
+ const init_url_translate = () => {
4
+ const $ = jQuery;
5
+
6
+ const execute = () => {
7
+ let old_text = {}
8
+
9
+ const edit_weglot_post_name = function(e) {
10
+ const code = $(this).data('lang')
11
+ const post_name = slugify($(`#lang-${code}`).val(), {
12
+ lower: true,
13
+ replacement: '-'
14
+ });
15
+
16
+ $(`#text-edit-${code}`).text( post_name );
17
+
18
+ $(`#lang-${code}`).hide();
19
+ $(this).hide()
20
+ $(`.button-weglot-lang[data-lang=${code}]`).show()
21
+
22
+ $.ajax({
23
+ url: ajaxurl,
24
+ method: "POST",
25
+ data: {
26
+ action: "weglot_post_name",
27
+ lang: code,
28
+ id: $("#weglot_post_id").data('id'),
29
+ post_name: post_name
30
+ },
31
+ success: function(res) {
32
+ if(res.data && res.data.code && res.data.code === 'same_post_name'){
33
+ $(`#text-edit-${code}`).text(old_text[code]);
34
+ $(`#lang-${code}`).val('');
35
+ return
36
+ }
37
+ else if (res.data && res.data.code && res.data.code ==='not_available'){
38
+ $(`#weglot_permalink_not_available_${code}`).show();
39
+ $(`#lang-${code}`).val("");
40
+ setTimeout(() => {
41
+ $(`#weglot_permalink_not_available_${code}`).hide();
42
+ }, 5000);
43
+ }
44
+
45
+ $(`#text-edit-${code}`).text(res.data.result.slug);
46
+ }
47
+ });
48
+ }
49
+
50
+ $(".button-weglot-lang").each((key, itm) => {
51
+ $(itm).on('click', function (e) {
52
+ e.preventDefault()
53
+
54
+ const code = $(this).data('lang')
55
+ const text = $(`#text-edit-${code}`).text();
56
+ old_text[code] = text
57
+
58
+ $(`#text-edit-${code}`).text(' ');
59
+ $(`#lang-${code}`).val(text).show();
60
+ $(`.button-weglot-lang-submit[data-lang=${code}]`).show();
61
+ $(this).hide()
62
+ })
63
+
64
+ const code = $(itm).data('lang')
65
+
66
+ $(`.button-weglot-lang-submit[data-lang=${code}]`)
67
+ .on("click", edit_weglot_post_name);
68
+ })
69
+
70
+ $(".weglot_reset").each((key, itm) => {
71
+ $(itm).on("click", function(e) {
72
+ e.preventDefault();
73
+
74
+ const code = $(this).data("lang");
75
+ const custom_url = $(this).attr('href')
76
+ const id = $(this).data('id')
77
+
78
+ $.ajax({
79
+ url: ajaxurl,
80
+ method: "POST",
81
+ data: {
82
+ action: "weglot_reset_custom_url",
83
+ code_lang: code,
84
+ id: id,
85
+ custom_url: custom_url
86
+ },
87
+ success: function(res) {
88
+ $(`#text-edit-${code}`).text(
89
+ res.data.result.slug
90
+ );
91
+ }
92
+ });
93
+
94
+ });
95
+
96
+ });
97
+ };
98
+
99
+ document.addEventListener("DOMContentLoaded", () => {
100
+ execute();
101
+ });
102
+
103
+ }
104
+
105
+ export default init_url_translate
app/javascripts/{admin-button-preview.js → settings/admin-button-preview.js} RENAMED
File without changes
app/javascripts/{admin-change-country.js → settings/admin-change-country.js} RENAMED
File without changes
app/javascripts/{admin-check-api-key.js → settings/admin-check-api-key.js} RENAMED
File without changes
app/javascripts/{admin-exclusion.js → settings/admin-exclusion.js} RENAMED
File without changes
app/javascripts/{admin-prevent-save-form.js → settings/admin-prevent-save-form.js} RENAMED
File without changes
app/javascripts/{admin-select.js → settings/admin-select.js} RENAMED
@@ -87,17 +87,36 @@ const init_admin_select = function(){
87
  let work_original_language = $("#original_language").val()
88
 
89
  $("#original_language").on("change", function (e) {
 
90
  const new_destination_option = work_original_language;
91
  work_original_language = e.target.value;
92
-
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
  destination_selectize[0].selectize.addOption(new_option);
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  });
102
 
103
 
87
  let work_original_language = $("#original_language").val()
88
 
89
  $("#original_language").on("change", function (e) {
90
+ const old_original_language = work_original_language;
91
  const new_destination_option = work_original_language;
92
  work_original_language = e.target.value;
 
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);
104
 
105
+
106
+ const is_fullname = $("#is_fullname").is(":checked")
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
 
app/javascripts/{admin-weglot-box.js → settings/admin-weglot-box.js} RENAMED
File without changes
app/styles/admin.scss CHANGED
@@ -11,6 +11,30 @@
11
  }
12
  }
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  .btn{
15
  background:$primary;
16
  display: inline-block;
11
  }
12
  }
13
 
14
+ .weglot_text_error {
15
+ color:red;
16
+ }
17
+
18
+ .weglot_reset{
19
+ text-decoration: underline;
20
+ font-style: italic;
21
+ &:hover{
22
+ cursor: pointer;
23
+ }
24
+ }
25
+
26
+ .weglot_custom_url{
27
+ border-bottom: 1px solid #ccc;
28
+ margin-bottom: 10px;
29
+ a{
30
+ margin: 5px 0px;
31
+ display: inline-block;
32
+ }
33
+ &--text_link{
34
+ margin-bottom: 4px;
35
+ }
36
+ }
37
+
38
  .btn{
39
  background:$primary;
40
  display: inline-block;
bootstrap.php CHANGED
@@ -73,6 +73,7 @@ abstract class Context_Weglot {
73
  '\WeglotWP\Actions\Migration_Weglot',
74
  '\WeglotWP\Third\Woocommerce\WC_Filter_Urls_Weglot',
75
  '\WeglotWP\Third\Amp\Amp_Enqueue_Weglot',
 
76
  ];
77
 
78
  self::$context->set_actions( $actions );
73
  '\WeglotWP\Actions\Migration_Weglot',
74
  '\WeglotWP\Third\Woocommerce\WC_Filter_Urls_Weglot',
75
  '\WeglotWP\Third\Amp\Amp_Enqueue_Weglot',
76
+ '\WeglotWP\Actions\Admin\Metabox_Url_Translate_Weglot',
77
  ];
78
 
79
  self::$context->set_actions( $actions );
dist/admin-css.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},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=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=11)}({11:function(e,t){}});
dist/admin-js.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function o(l){if(t[l])return t[l].exports;var a=t[l]={i:l,l:!1,exports:{}};return e[l].call(a.exports,a,a.exports,o),a.l=!0,a.exports}o.m=e,o.c=t,o.d=function(e,t,l){o.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:l})},o.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},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 l=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 l=t[0].selectize.getValue(),a=e("#li-button-tpl");if(0===a.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 c="";l.forEach(e=>{const t=weglot_languages.available.find(t=>t.code===e);let o="";r&&(o=n?t.local:e.toUpperCase()),c+=a.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 l=e("#original_language").val();e("#original_language").on("change",function(e){const o=l;l=e.target.value,t[0].selectize.removeOption(l);const a=weglot_languages.available.find(e=>e.code===o);t[0].selectize.addOption(a)}),o(),window.addEventListener("weglotCheckApi",e=>{let o=1e3;const l=e.detail.answer.plan;l<=0||weglot_languages.plans.starter_free.ids.indexOf(l)>=0?o=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(l)>=0&&(o=weglot_languages.plans.business.limit_language),t[0].selectize.settings.maxItems=o})})()})};var a=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{e("#weglot-box-first-settings .weglot-btn-close").on("click",function(t){t.preventDefault(),e("#weglot-box-first-settings").hide()})})};var n=function(){jQuery;const e=()=>{const e=document.querySelector("#tpl-exclusion-url"),t=document.querySelector("#tpl-exclusion-block"),o=document.querySelector("#container-exclude_urls"),l=document.querySelector("#container-exclude_blocks");function a(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-url")&&document.querySelector("#js-add-exclude-url").addEventListener("click",t=>{t.preventDefault(),o.insertAdjacentHTML("beforeend",e.innerHTML),document.querySelector("#container-exclude_urls .item-exclude:last-child .js-btn-remove").addEventListener("click",a)}),document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",e=>{e.preventDefault(),l.insertAdjacentHTML("beforeend",t.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",a)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",a)})};document.addEventListener("DOMContentLoaded",()=>{e()})};var r=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{0!==e(".weglot-preview").length&&(()=>{let t=e("#type_flags").val(),o=[];o.push(e(".country-selector label").data("code-language")),e(".country-selector li").each((t,l)=>{o.push(e(l).data("code-language"))});const l=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 l=o.target.value;e(".country-selector label, .country-selector li").addClass(`flag-${l}`),t=l});const a=()=>{const t=l.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),a=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(a),e(".country-selector li").each((t,a)=>{const n=l.find(t=>t.code===e(a).data("code-language")),r=o?n.local:n.code.toUpperCase();e(a).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?a():(e(".country-selector label a, .country-selector label span").text(""),e(".country-selector li a, .country-selector li span").each((t,o)=>{e(o).text("")}))}),e("#is_fullname").on("change",function(t){if(e("#with_name").is(":checked"))if(t.target.checked)a();else{const t=l.find(t=>t.code===e(".country-selector label").data("code-language"));e(".country-selector label a, .country-selector label span").text(t.code.toUpperCase()),e(".country-selector li").each((t,o)=>{const a=l.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(a.code.toUpperCase()),e(o).find("span").text(a.code.toUpperCase())})}}),e("#override_css").on("keyup",function(t){e("#weglot-css-inline").text(t.target.value)})})()})};var s=function(){const e=jQuery,t=()=>{e("#api_key").blur(function(){var t=e(this).val();if(0===t.length)return e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>'),void e("#wrap-weglot #submit").prop("disabled",!0);e.getJSON("https://weglot.com/api/user-info?api_key="+t,t=>{e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-okkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!1);const o=new CustomEvent("weglotCheckApi",{detail:t});window.dispatchEvent(o)}).fail(function(){e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!0)})})};document.addEventListener("DOMContentLoaded",()=>{t()})};var c=function(){const e=jQuery;"undefined"!=typeof weglot_css&&e("#weglot-css-flag-css").text(weglot_css.flag_css);const t=()=>{e(".flag-style-openclose").on("click",function(){e(".flag-style-wrapper").toggle()}),e("select.flag-en-type, select.flag-es-type, select.flag-pt-type, select.flag-fr-type, select.flag-ar-type").on("change",function(){!function(){var t=new Array,o=new Array,l=new Array,a=new Array,n=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],l[1]=[1740,5921,528,3504],a[1]=[2760,736,2856,4416],a[2]=[3840,1280,2712,4224],a[3]=[5700,7201,5016,2400],a[4]=[2220,4160,1632,1944],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];var r=e("select.flag-en-type").val(),s=e("select.flag-es-type").val(),c=e("select.flag-pt-type").val(),g=e("select.flag-fr-type").val(),i=e("select.flag-ar-type").val(),f=r<=0?"":".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -"+t[r][0]+"px 0; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -"+t[r][1]+"px 0; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -"+t[r][2]+"px 0; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -"+t[r][3]+"px 0; } ",u=s<=0?"":".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -"+o[s][0]+"px 0; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -"+o[s][1]+"px 0; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -"+o[s][2]+"px 0; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -"+o[s][3]+"px 0; } ",d=c<=0?"":".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -"+l[c][0]+"px 0; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -"+l[c][1]+"px 0; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -"+l[c][2]+"px 0; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -"+l[c][3]+"px 0; } ",p=g<=0?"":".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -"+a[g][0]+"px 0; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -"+a[g][1]+"px 0; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -"+a[g][2]+"px 0; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -"+a[g][3]+"px 0; } ",w=i<=0?"":".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -"+n[i][0]+"px 0; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -"+n[i][1]+"px 0; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -"+n[i][2]+"px 0; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -"+n[i][3]+"px 0; } ";e("#flag_css, #weglot-css-flag-css").text(f+u+d+p+w)}()})};document.addEventListener("DOMContentLoaded",()=>{t()})};var g=function(){};o(2),o(1);l(),n(),a(),r(),s(),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,l=new Array(o),a=this,n=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(a[r],r,a)&&(l[n++]=a[r]);else for(;++r!==o;)r in this&&e.call(t,a[r],r,a)&&(l[n++]=a[r]);return l.length=n,l})},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 l=arguments[1],a=0;a<o;){var n=t[a];if(e.call(l,n,a,t))return n;a++}},configurable:!0,writable:!0})}]);
1
+ !function(e){var t={};function o(l){if(t[l])return t[l].exports;var a=t[l]={i:l,l:!1,exports:{}};return e[l].call(a.exports,a,a.exports,o),a.l=!0,a.exports}o.m=e,o.c=t,o.d=function(e,t,l){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:l})},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 l=Object.create(null);if(o.r(l),Object.defineProperty(l,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)o.d(l,a,function(t){return e[t]}.bind(null,a));return l},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.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 l=arguments[1],a=0;a<o;){var n=t[a];if(e.call(l,n,a,t))return n;a++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var o=this.length>>>0,l=new Array(o),a=this,n=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(a[r],r,a)&&(l[n++]=a[r]);else for(;++r!==o;)r in this&&e.call(t,a[r],r,a)&&(l[n++]=a[r]);return l.length=n,l})},,,function(e,t,o){"use strict";o.r(t);var l=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 l=t[0].selectize.getValue(),a=e("#li-button-tpl");if(0===a.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 c="";l.forEach(e=>{const t=weglot_languages.available.find(t=>t.code===e);let o="";r&&(o=n?t.local:e.toUpperCase()),c+=a.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 l=e("#original_language").val();e("#original_language").on("change",function(o){const a=l,n=l;l=o.target.value,t[0].selectize.removeOption(l);const r=weglot_languages.available.find(e=>e.code===n),s=weglot_languages.available.find(e=>e.code===l);t[0].selectize.addOption(r);const c=e("#is_fullname").is(":checked");let g="";e("#with_name").is(":checked")&&(g=c?s.local:s.code.toUpperCase()),e(".wgcurrent.wg-li").removeClass(a).addClass(l).attr("data-code-language",l).find("span").html(g)}),o(),window.addEventListener("weglotCheckApi",e=>{let o=1e3;const l=e.detail.answer.plan;l<=0||weglot_languages.plans.starter_free.ids.indexOf(l)>=0?o=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(l)>=0&&(o=weglot_languages.plans.business.limit_language),t[0].selectize.settings.maxItems=o})})()})};var a=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{e("#weglot-box-first-settings .weglot-btn-close").on("click",function(t){t.preventDefault(),e("#weglot-box-first-settings").hide()})})};var n=function(){jQuery;const e=()=>{const e=document.querySelector("#tpl-exclusion-url"),t=document.querySelector("#tpl-exclusion-block"),o=document.querySelector("#container-exclude_urls"),l=document.querySelector("#container-exclude_blocks");function a(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-url")&&document.querySelector("#js-add-exclude-url").addEventListener("click",t=>{t.preventDefault(),o.insertAdjacentHTML("beforeend",e.innerHTML),document.querySelector("#container-exclude_urls .item-exclude:last-child .js-btn-remove").addEventListener("click",a)}),document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",e=>{e.preventDefault(),l.insertAdjacentHTML("beforeend",t.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",a)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",a)})};document.addEventListener("DOMContentLoaded",()=>{e()})};var r=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{0!==e(".weglot-preview").length&&(()=>{let t=e("#type_flags").val(),o=[];o.push(e(".country-selector label").data("code-language")),e(".country-selector li").each((t,l)=>{o.push(e(l).data("code-language"))});const l=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 l=o.target.value;e(".country-selector label, .country-selector li").addClass(`flag-${l}`),t=l});const a=()=>{const t=l.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),a=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(a),e(".country-selector li").each((t,a)=>{const n=l.find(t=>t.code===e(a).data("code-language")),r=o?n.local:n.code.toUpperCase();e(a).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?a():(e(".country-selector label a, .country-selector label span").text(""),e(".country-selector li a, .country-selector li span").each((t,o)=>{e(o).text("")}))}),e("#is_fullname").on("change",function(t){if(e("#with_name").is(":checked"))if(t.target.checked)a();else{const t=l.find(t=>t.code===e(".country-selector label").data("code-language"));e(".country-selector label a, .country-selector label span").text(t.code.toUpperCase()),e(".country-selector li").each((t,o)=>{const a=l.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(a.code.toUpperCase()),e(o).find("span").text(a.code.toUpperCase())})}}),e("#override_css").on("keyup",function(t){e("#weglot-css-inline").text(t.target.value)})})()})};var s=function(){const e=jQuery,t=()=>{e("#api_key").blur(function(){var t=e(this).val();if(0===t.length)return e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>'),void e("#wrap-weglot #submit").prop("disabled",!0);e.getJSON("https://weglot.com/api/user-info?api_key="+t,t=>{e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-okkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!1);const o=new CustomEvent("weglotCheckApi",{detail:t});window.dispatchEvent(o)}).fail(function(){e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!0)})})};document.addEventListener("DOMContentLoaded",()=>{t()})};var c=function(){const e=jQuery;"undefined"!=typeof weglot_css&&e("#weglot-css-flag-css").text(weglot_css.flag_css);const t=()=>{e(".flag-style-openclose").on("click",function(){e(".flag-style-wrapper").toggle()}),e("select.flag-en-type, select.flag-es-type, select.flag-pt-type, select.flag-fr-type, select.flag-ar-type").on("change",function(){!function(){var t=new Array,o=new Array,l=new Array,a=new Array,n=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],l[1]=[1740,5921,528,3504],a[1]=[2760,736,2856,4416],a[2]=[3840,1280,2712,4224],a[3]=[5700,7201,5016,2400],a[4]=[2220,4160,1632,1944],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];var r=e("select.flag-en-type").val(),s=e("select.flag-es-type").val(),c=e("select.flag-pt-type").val(),g=e("select.flag-fr-type").val(),i=e("select.flag-ar-type").val(),f=r<=0?"":".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -"+t[r][0]+"px 0; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -"+t[r][1]+"px 0; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -"+t[r][2]+"px 0; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -"+t[r][3]+"px 0; } ",u=s<=0?"":".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -"+o[s][0]+"px 0; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -"+o[s][1]+"px 0; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -"+o[s][2]+"px 0; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -"+o[s][3]+"px 0; } ",d=c<=0?"":".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -"+l[c][0]+"px 0; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -"+l[c][1]+"px 0; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -"+l[c][2]+"px 0; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -"+l[c][3]+"px 0; } ",p=g<=0?"":".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -"+a[g][0]+"px 0; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -"+a[g][1]+"px 0; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -"+a[g][2]+"px 0; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -"+a[g][3]+"px 0; } ",w=i<=0?"":".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -"+n[i][0]+"px 0; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -"+n[i][1]+"px 0; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -"+n[i][2]+"px 0; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -"+n[i][3]+"px 0; } ";e("#flag_css, #weglot-css-flag-css").text(f+u+d+p+w)}()})};document.addEventListener("DOMContentLoaded",()=>{t()})};var g=function(){};o(0),o(1);l(),n(),a(),r(),s(),c(),g()}]);
dist/css/admin-css.css CHANGED
@@ -330,6 +330,24 @@
330
  color: #a6a6a6;
331
  display: block; }
332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  .btn {
334
  background: #335ee2;
335
  display: inline-block;
330
  color: #a6a6a6;
331
  display: block; }
332
 
333
+ .weglot_text_error {
334
+ color: red; }
335
+
336
+ .weglot_reset {
337
+ text-decoration: underline;
338
+ font-style: italic; }
339
+ .weglot_reset:hover {
340
+ cursor: pointer; }
341
+
342
+ .weglot_custom_url {
343
+ border-bottom: 1px solid #ccc;
344
+ margin-bottom: 10px; }
345
+ .weglot_custom_url a {
346
+ margin: 5px 0px;
347
+ display: inline-block; }
348
+ .weglot_custom_url--text_link {
349
+ margin-bottom: 4px; }
350
+
351
  .btn {
352
  background: #335ee2;
353
  display: inline-block;
dist/front-amp-css.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},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){}});
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-css.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},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=13)}({13: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-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,{configurable:!1,enumerable:!0,get:n})},o.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},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=3)}({3:function(e,t){document.addEventListener("DOMContentLoaded",function(e){const t=document.querySelector(".country-selector");if(!t)return;const o=(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=3)}({3:function(e,t){document.addEventListener("DOMContentLoaded",function(e){const t=document.querySelector(".country-selector");if(!t)return;const o=(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 ADDED
@@ -0,0 +1 @@
 
1
+ !function(e){var t={};function n(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return e[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(a,o,function(t){return e[t]}.bind(null,o));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=5)}([function(e,t){Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var a=arguments[1],o=0;o<n;){var r=t[o];if(e.call(a,r,o,t))return r;o++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var n=this.length>>>0,a=new Array(n),o=this,r=0,i=-1;if(void 0===t)for(;++i!==n;)i in this&&e(o[i],i,o)&&(a[r++]=o[i]);else for(;++i!==n;)i in this&&e.call(t,o[i],i,o)&&(a[r++]=o[i]);return a.length=r,a})},function(e,t,n){!function(t,n,a){e.exports=a(),e.exports.default=a()}(0,0,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})},,,function(e,t,n){"use strict";n.r(t);n(0),n(1);var a=n(2),o=n.n(a);(()=>{const e=jQuery,t=()=>{let t={};const n=function(n){const a=e(this).data("lang"),r=o()(e(`#lang-${a}`).val(),{lower:!0,replacement:"-"});e(`#text-edit-${a}`).text(r),e(`#lang-${a}`).hide(),e(this).hide(),e(`.button-weglot-lang[data-lang=${a}]`).show(),e.ajax({url:ajaxurl,method:"POST",data:{action:"weglot_post_name",lang:a,id:e("#weglot_post_id").data("id"),post_name:r},success:function(n){if(n.data&&n.data.code&&"same_post_name"===n.data.code)return e(`#text-edit-${a}`).text(t[a]),void e(`#lang-${a}`).val("");n.data&&n.data.code&&"not_available"===n.data.code&&(e(`#weglot_permalink_not_available_${a}`).show(),e(`#lang-${a}`).val(""),setTimeout(()=>{e(`#weglot_permalink_not_available_${a}`).hide()},5e3)),e(`#text-edit-${a}`).text(n.data.result.slug)}})};e(".button-weglot-lang").each((a,o)=>{e(o).on("click",function(n){n.preventDefault();const a=e(this).data("lang"),o=e(`#text-edit-${a}`).text();t[a]=o,e(`#text-edit-${a}`).text(" "),e(`#lang-${a}`).val(o).show(),e(`.button-weglot-lang-submit[data-lang=${a}]`).show(),e(this).hide()});const r=e(o).data("lang");e(`.button-weglot-lang-submit[data-lang=${r}]`).on("click",n)}),e(".weglot_reset").each((t,n)=>{e(n).on("click",function(t){t.preventDefault();const n=e(this).data("lang"),a=e(this).attr("href"),o=e(this).data("id");e.ajax({url:ajaxurl,method:"POST",data:{action:"weglot_reset_custom_url",code_lang:n,id:o,custom_url:a},success:function(t){e(`#text-edit-${n}`).text(t.data.result.slug)}})})})};document.addEventListener("DOMContentLoaded",()=>{t()})})()}]);
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === Weglot Translate - Translate your WP website ===
2
  Contributors: remyb92
3
  Tags: translate,translation,language,multilingual,bilingual,international,localization,multilanguage,multi language,translations,translator,multilangues,traduction,traducteur,ubersetzung,mehrsprachig,traduccion,traduzione,vertaling,vertaler,meertalig
4
  Requires at least: 4.5
5
  Tested up to: 4.9
6
  Requires PHP: 5.4
7
- Stable tag: 2.0.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -152,6 +152,13 @@ See changelog for upgrade changes.
152
 
153
  == Changelog ==
154
 
 
 
 
 
 
 
 
155
  = 2.0.7 (31/08/2018) =
156
  * Bugfix: Ajax load media library
157
  * Improve choice original and destination language
1
+ === Translate WP website - Weglot Translate ===
2
  Contributors: remyb92
3
  Tags: translate,translation,language,multilingual,bilingual,international,localization,multilanguage,multi language,translations,translator,multilangues,traduction,traducteur,ubersetzung,mehrsprachig,traduccion,traduzione,vertaling,vertaler,meertalig
4
  Requires at least: 4.5
5
  Tested up to: 4.9
6
  Requires PHP: 5.4
7
+ Stable tag: 2.1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
152
 
153
  == Changelog ==
154
 
155
+ = 2.1.0 (25/09/2018) =
156
+ * New feature: Custom URL
157
+ * Bugfix : Translate AJAX with return JSON on error
158
+ * Bugfix : Backslash on function PHP
159
+ * Bugfix : Replace links href on JSON translate
160
+ * Bugfix : Compatibility with theme use ob_start
161
+
162
  = 2.0.7 (31/08/2018) =
163
  * Bugfix: Ajax load media library
164
  * Improve choice original and destination language
src/actions/admin/class-admin-enqueue-weglot.php CHANGED
@@ -35,6 +35,22 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
35
  */
36
  public function hooks() {
37
  add_action( 'admin_enqueue_scripts', [ $this, 'weglot_admin_enqueue_scripts' ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
40
 
35
  */
36
  public function hooks() {
37
  add_action( 'admin_enqueue_scripts', [ $this, 'weglot_admin_enqueue_scripts' ] );
38
+ add_action( 'admin_enqueue_scripts', [ $this, 'weglot_admin_enqueue_scripts_metaboxes' ] );
39
+ }
40
+
41
+ /**
42
+ * @since 2.1.0
43
+ *
44
+ * @return void
45
+ * @param mixed $page
46
+ */
47
+ public function weglot_admin_enqueue_scripts_metaboxes( $page ) {
48
+ if ( ! in_array( $page, [ 'post.php' ] ) ) { //phpcs:ignore
49
+ return;
50
+ }
51
+
52
+ wp_enqueue_script( 'weglot-admin-metaboxes-js', WEGLOT_URL_DIST . '/metaboxes-js.js', [ 'jquery' ] );
53
+ wp_enqueue_style( 'weglot-admin-css', WEGLOT_URL_DIST . '/css/admin-css.css', [], WEGLOT_VERSION );
54
  }
55
 
56
 
src/actions/admin/class-metabox-url-translate-weglot.php ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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', [ $this, 'add_meta_boxes_url_translate' ] );
36
+ add_action( 'save_post', [ $this, 'save_post_meta_boxes_url_translate' ] );
37
+ add_action( 'wp_ajax_weglot_post_name', [ $this, 'weglot_post_name' ] );
38
+ add_action( 'wp_ajax_weglot_reset_custom_url', [ $this, 'weglot_reset_custom_url' ] );
39
+
40
+ add_filter( 'wp_insert_post_data', [ $this, 'weglot_wp_insert_post_data' ], 10, 2 );
41
+ add_filter( 'wp_unique_post_slug', [ $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
+ 'code' => 'missing_parameter',
58
+ ] );
59
+ return;
60
+ }
61
+
62
+ $code_lang = sanitize_text_field( wp_unslash( $_POST['code_lang'] ) ); //phpcs:ignore
63
+ $post_name_weglot = sanitize_text_field( wp_unslash( $_POST['custom_url'] ) ); //phpcs:ignore
64
+
65
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
66
+
67
+ if ( isset( $custom_urls[ $code_lang ] ) && isset( $custom_urls[ $code_lang ][ $post_name_weglot ] ) ) {
68
+ unset( $custom_urls[ $code_lang ] [ $post_name_weglot ] );
69
+ $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
70
+ }
71
+
72
+ $post = get_post( $_POST['id'] ); //phpcs:ignore
73
+
74
+ wp_send_json_success( [
75
+ 'result' => [
76
+ 'slug' => $post->post_name,
77
+ ],
78
+ ] );
79
+ }
80
+
81
+ /**
82
+ * Improve wp_unique_post_slug with custom URLs weglot
83
+ * @since 2.1.0
84
+ * @param string $slug
85
+ * @param array $custom_urls
86
+ * @param integer $suffix
87
+ * @return string
88
+ */
89
+ protected function search_unique_key_post_name( $slug, $custom_urls, $suffix = 2 ) {
90
+ foreach ( $custom_urls as $key_code => $urls ) {
91
+ if ( isset( $urls[ $slug ] ) ) {
92
+ $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
93
+ return $this->search_unique_key_post_name( $alt_post_name, $custom_urls, ++$suffix );
94
+ }
95
+ }
96
+
97
+ return $slug;
98
+ }
99
+
100
+
101
+ /**
102
+ * Filters the unique post slug.
103
+ *
104
+ * @since 2.1.0
105
+ *
106
+ * @param string $slug The post slug.
107
+ */
108
+ public function weglot_wp_unique_post_slug( $slug ) {
109
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
110
+ return $this->search_unique_key_post_name( $slug, $custom_urls );
111
+ }
112
+
113
+ /**
114
+ * @since 2.1.0
115
+ * @return void
116
+ */
117
+ public function weglot_post_name() {
118
+ $weglot_post_name = ( isset( $_POST['post_name'] ) && ! empty( $_POST['post_name'] ) ) ? sanitize_title( $_POST['post_name'] ) : null ; //phpcs:ignore
119
+ $code_language = ( isset( $_POST['lang'] ) && ! empty( $_POST['lang'] ) ) ? sanitize_text_field( $_POST['lang'] ) : null ; //phpcs:ignore
120
+ $post_id = ( isset( $_POST['id'] ) && ! empty( $_POST['id'] ) ) ? sanitize_text_field( $_POST['id'] ) : null ; //phpcs:ignore
121
+
122
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
123
+
124
+ if ( ! $weglot_post_name || ! $code_language || ! $post_id ) {
125
+ wp_send_json_error( [
126
+ 'success' => false,
127
+ 'code' => 'missing_parameter',
128
+ ] );
129
+ return;
130
+ }
131
+
132
+ // Check if not an autosave.
133
+ if ( wp_is_post_autosave( $post_id ) ) {
134
+ wp_send_json_error( [
135
+ 'success' => false,
136
+ ] );
137
+ return;
138
+ }
139
+
140
+ // Check if not a revision.
141
+ if ( wp_is_post_revision( $post_id ) ) {
142
+ wp_send_json_error( [
143
+ 'success' => false,
144
+ ] );
145
+ return;
146
+ }
147
+
148
+
149
+ $post = get_post( $post_id );
150
+ if ( $post->post_name === $weglot_post_name ) {
151
+ if ( in_array( $post->post_name, $custom_urls[ $code_language ] ) ) { // phpcs:ignore
152
+ $key_post_name = array_search( $post->post_name, $custom_urls[ $code_language ] );// phpcs:ignore
153
+ unset( $custom_urls[ $code_language ][ $key_post_name ] );
154
+
155
+ $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
156
+
157
+ wp_send_json_success( [
158
+ 'success' => true,
159
+ 'result' => [
160
+ 'slug' => $weglot_post_name,
161
+ ],
162
+ ] );
163
+ return;
164
+ }
165
+
166
+ wp_send_json_success( [
167
+ 'code' => 'same_post_name',
168
+ ] );
169
+
170
+ return;
171
+ }
172
+
173
+ if ( isset( $custom_urls[ $code_language ] ) ) {
174
+ // Same use
175
+ if ( isset( $custom_urls[ $code_language ][ $weglot_post_name ] ) && $custom_urls[ $code_language ][ $weglot_post_name ] === $post->post_name ) {
176
+ wp_send_json_success( [
177
+ 'code' => 'same_post_name',
178
+ ] );
179
+ return;
180
+ }
181
+
182
+ if ( in_array( $post->post_name, $custom_urls[ $code_language ] ) ) { // phpcs:ignore
183
+ $key_post_name = array_search( $post->post_name, $custom_urls[ $code_language ] );// phpcs:ignore
184
+ unset( $custom_urls[ $code_language ][ $key_post_name ] );
185
+ }
186
+ }
187
+
188
+ $weglot_unique_slug = wp_unique_post_slug( trim( $weglot_post_name ), $post->ID, $post->post_status, $post->post_type, $post->post_parent );
189
+
190
+ $custom_urls[ $code_language ] [ $weglot_unique_slug ] = $post->post_name;
191
+ $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
192
+
193
+ wp_send_json_success( [
194
+ 'success' => true,
195
+ 'result' => [
196
+ 'slug' => $weglot_unique_slug,
197
+ ],
198
+ ] );
199
+ }
200
+
201
+ /**
202
+ * @since 2.1.0
203
+ * @return void
204
+ */
205
+ public function add_meta_boxes_url_translate() {
206
+ add_meta_box( 'weglot-url-translate', __( 'Weglot URL Translate', 'weglot' ), [ $this, 'weglot_url_translate_box' ] );
207
+ }
208
+
209
+ /**
210
+ * @since 2.1.0
211
+ * @return void
212
+ * @param mixed $post
213
+ */
214
+ public function weglot_url_translate_box( $post ) {
215
+ $this->custom_urls = $this->option_services->get_option( 'custom_urls' );
216
+ include_once WEGLOT_TEMPLATES_ADMIN_METABOXES . '/url-translate.php';
217
+ }
218
+
219
+ /**
220
+ * Prevent change post_name
221
+ * @since 2.1.0
222
+ * @param array $data
223
+ * @param array $postarr
224
+ * @return array
225
+ */
226
+ public function weglot_wp_insert_post_data( $data, $postarr ) {
227
+ $post = get_post( $postarr['ID'] );
228
+ if ( $post ) {
229
+ $this->old_post_name = $post->post_name;
230
+ $this->new_post_name = $data['post_name'];
231
+ }
232
+ return $data;
233
+ }
234
+
235
+ /**
236
+ * @since 2.1.0
237
+ *
238
+ * @param mixed $post_id
239
+ * @return void
240
+ */
241
+ public function save_post_meta_boxes_url_translate( $post_id ) {
242
+
243
+ // Add nonce for security and authentication.
244
+ $post_name_weglot = isset( $_POST[ Helper_Post_Meta_Weglot::POST_NAME_WEGLOT ] ) ? $_POST[ Helper_Post_Meta_Weglot::POST_NAME_WEGLOT ] : []; //phpcs:ignore
245
+
246
+ if ( ! isset( $post_name_weglot ) ) {
247
+ return;
248
+ }
249
+
250
+ // Check if user has permissions to save data.
251
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
252
+ return;
253
+ }
254
+
255
+ // Check if not an autosave.
256
+ if ( wp_is_post_autosave( $post_id ) ) {
257
+ return;
258
+ }
259
+
260
+ // Check if not a revision.
261
+ if ( wp_is_post_revision( $post_id ) ) {
262
+ return;
263
+ }
264
+
265
+ // $post = get_post( $post_id );
266
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
267
+
268
+ // Update new post_name
269
+ if ( $this->old_post_name !== $this->new_post_name ) {
270
+ foreach ( $custom_urls as $key_code => $urls ) {
271
+ $key_search = array_search( $this->old_post_name, $urls ); // phpcs:ignore
272
+ if ( false === $key_search ) {
273
+ continue;
274
+ }
275
+
276
+ $custom_urls[ $key_code ][ $key_search ] = $this->new_post_name;
277
+ }
278
+ $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
279
+ }
280
+
281
+
282
+
283
+ }
284
+ }
src/actions/front/class-translate-page-weglot.php CHANGED
@@ -7,12 +7,14 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
10
 
11
  use Weglot\Client\Api\Enum\BotType;
12
  use Weglot\Client\Client;
13
  use Weglot\Util\Server;
14
  use Weglot\Client\Api\Exception\ApiError;
15
 
 
16
  /**
17
  * Translate page
18
  *
@@ -44,7 +46,8 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
44
  */
45
  public function hooks() {
46
  $no_translate = false;
47
- $action_ajax_no_translate = apply_filters( 'weglot_action_ajax_no_translate', [ 'add-menu-item', 'query-attachments' ] );
 
48
  if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && in_array( $_POST['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
49
  $no_translate = true;
50
  }
@@ -71,7 +74,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
71
  $this->prepare_request_uri();
72
  $this->prepare_rtl_language();
73
 
74
- add_action( 'init', [ $this, 'weglot_init' ] );
75
  add_action( 'wp_head', [ $this, 'weglot_href_lang' ] );
76
  }
77
 
@@ -128,7 +131,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
128
  * @version 2.0.4
129
  *
130
  * @param array $array
131
- * @return void
132
  */
133
  public function translate_array( $array ) {
134
  $array_not_ajax_html = apply_filters( 'weglot_array_not_ajax_html', [ 'redirecturl', 'url' ] );
@@ -149,6 +152,30 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
149
  return $array;
150
  }
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  /**
153
  * @since 2.0
154
  *
@@ -185,17 +212,74 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
185
  }
186
 
187
  /**
188
- * @since 2.0
189
- *
190
  * @return void
191
  */
192
- public function prepare_request_uri() {
193
- // Use for good process on URL
194
  $_SERVER['REQUEST_URI'] = str_replace(
195
  '/' . $this->request_url_services->get_current_language( false ) . '/',
196
  '/',
197
  $_SERVER['REQUEST_URI'] //phpcs:ignore
198
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  }
200
 
201
  /**
@@ -234,9 +318,16 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
234
  public function weglot_treat_page( $content ) {
235
  $this->current_language = $this->request_url_services->get_current_language(); // Need to reset
236
  $allowed = $this->option_services->get_option( 'allowed' );
 
 
 
237
 
238
  if ( ! $allowed ) {
239
  $content = $this->weglot_render_dom( $content );
 
 
 
 
240
  return $content . '<!--Not allowed-->';
241
  }
242
 
@@ -249,15 +340,12 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
249
 
250
  $parser = $this->parser_services->get_parser();
251
 
252
- // Choose type translate
253
- $type = ( $this->is_json( $content ) ) ? 'json' : 'html';
254
- $type = apply_filters( 'weglot_type_treat_page', $type );
255
-
256
  try {
257
  switch ( $type ) {
258
  case 'json':
259
- $json = json_decode( $content, true );
260
  $content = $this->translate_array( $json );
 
261
  $content = apply_filters( 'weglot_json_treat_page', $content );
262
 
263
  return wp_json_encode( $content );
@@ -284,13 +372,17 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
284
 
285
  }
286
  } catch ( ApiError $e ) {
287
- $content .= '<!--Weglot error API : ' . $this->remove_comments( $e->getMessage() ) . '-->';
 
 
288
  if ( strpos( $e->getMessage(), 'NMC' ) !== false ) {
289
  $this->option_services->set_option_by_key( 'allowed', false );
290
  }
291
  return $content;
292
  } catch ( \Exception $e ) {
293
- $content .= '<!--Weglot error : ' . $this->remove_comments( $e->getMessage() ) . '-->';
 
 
294
  return $content;
295
  }
296
  }
@@ -312,7 +404,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
312
  * @return boolean
313
  */
314
  public function is_json( $string ) {
315
- return is_string( $string ) && is_array( json_decode( $string, true ) ) && ( JSON_ERROR_NONE === json_last_error() ) ? true : false;
316
  }
317
 
318
  /**
@@ -335,6 +427,13 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
335
  $is_fullname = $options['is_fullname'];
336
  $with_name = $options['with_name'];
337
 
 
 
 
 
 
 
 
338
  foreach ( $languages_configured as $language ) {
339
  $shortcode_title = sprintf( '\[weglot_menu_title-%s\]', $language->getIso639() );
340
  $shortcode_title_without_bracket = sprintf( 'weglot_menu_title-%s', $language->getIso639() );
@@ -344,7 +443,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
344
  $shortcode_url_html = str_replace( '\[', '%5B', $shortcode_url );
345
  $shortcode_url_html = str_replace( '\]', '%5D', $shortcode_url_html );
346
 
347
- $url = $this->request_url_services->get_weglot_url();
348
 
349
  $name = '';
350
  if ( $with_name ) {
@@ -360,6 +459,23 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
360
  $link_menu .= '?no_lredirect=true';
361
  }
362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  // Compatibility Menu HTTPS if not work. Since 2.0.6
364
  if (
365
  (
@@ -371,6 +487,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
371
  $link_menu = str_replace( 'http', 'https', $link_menu );
372
  }
373
 
 
374
  $dom = preg_replace( '#' . $shortcode_url . '#i', $link_menu, $dom );
375
  $dom = preg_replace( '#' . $shortcode_url_html . '#i', $link_menu, $dom );
376
  }
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
11
 
12
  use Weglot\Client\Api\Enum\BotType;
13
  use Weglot\Client\Client;
14
  use Weglot\Util\Server;
15
  use Weglot\Client\Api\Exception\ApiError;
16
 
17
+
18
  /**
19
  * Translate page
20
  *
46
  */
47
  public function hooks() {
48
  $no_translate = false;
49
+ $action_ajax_no_translate = [ 'add-menu-item', 'query-attachments' ];
50
+
51
  if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && in_array( $_POST['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
52
  $no_translate = true;
53
  }
74
  $this->prepare_request_uri();
75
  $this->prepare_rtl_language();
76
 
77
+ add_action( 'init', [ $this, 'weglot_init' ], 11 );
78
  add_action( 'wp_head', [ $this, 'weglot_href_lang' ] );
79
  }
80
 
131
  * @version 2.0.4
132
  *
133
  * @param array $array
134
+ * @return array
135
  */
136
  public function translate_array( $array ) {
137
  $array_not_ajax_html = apply_filters( 'weglot_array_not_ajax_html', [ 'redirecturl', 'url' ] );
152
  return $array;
153
  }
154
 
155
+ /**
156
+ * Replace links for JSON translate
157
+ *
158
+ * @since 2.1.0
159
+ *
160
+ * @param array $array
161
+ * @return array
162
+ */
163
+ public function replace_link_array( $array ){
164
+ $array_not_ajax_html = apply_filters( 'weglot_array_not_ajax_html', [ 'redirecturl', 'url' ] );
165
+
166
+ foreach ( $array as $key => $val ) {
167
+ if ( is_array( $val ) ) {
168
+ $array[ $key ] = $this->replace_link_array( $val );
169
+ } else {
170
+ if ( $this->is_ajax_html( $val ) ) {
171
+ $array[$key] = $this->weglot_replace_link($val);
172
+ }
173
+ }
174
+ }
175
+
176
+ return $array;
177
+ }
178
+
179
  /**
180
  * @since 2.0
181
  *
212
  }
213
 
214
  /**
215
+ * @since 2.1.0
 
216
  * @return void
217
  */
218
+ protected function request_uri_default() {
 
219
  $_SERVER['REQUEST_URI'] = str_replace(
220
  '/' . $this->request_url_services->get_current_language( false ) . '/',
221
  '/',
222
  $_SERVER['REQUEST_URI'] //phpcs:ignore
223
  );
224
+ return;
225
+ }
226
+
227
+ /**
228
+ * @since 2.0
229
+ * @version 2.1.0
230
+ * @return void
231
+ */
232
+ public function prepare_request_uri() {
233
+ $original_language = weglot_get_original_language();
234
+ $current_language = $this->request_url_services->get_current_language( false );
235
+
236
+ if ( $original_language === $current_language ) {
237
+ return;
238
+ }
239
+
240
+ $request_without_language = array_values(array_filter( explode( '/', str_replace(
241
+ '/' . $current_language . '/',
242
+ '/',
243
+ $_SERVER['REQUEST_URI'] //phpcs:ignore
244
+ ) ), 'strlen' ));
245
+
246
+ $index_entries = count( $request_without_language ) - 1;
247
+ if ( isset( $request_without_language[ $index_entries ] ) ) {
248
+ $slug_in_work = $request_without_language[ $index_entries ];
249
+ }
250
+
251
+ // Like is_home
252
+ if ( empty( $request_without_language ) || ! isset( $slug_in_work ) ) {
253
+ $this->request_uri_default();
254
+ return;
255
+ }
256
+
257
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
258
+
259
+ // No language configured
260
+ if ( ! isset( $custom_urls[ $current_language ] ) ) {
261
+ $this->request_uri_default();
262
+ return;
263
+ }
264
+
265
+ $key_slug = array_search( $slug_in_work, $custom_urls[ $current_language ] );
266
+
267
+ // No custom URL for this language with this slug
268
+ if ( ! isset( $custom_urls[ $current_language ][ $slug_in_work ] ) && false === $key_slug ) {
269
+ $this->request_uri_default();
270
+ return;
271
+ }
272
+
273
+ // Custom URL exist but not good slug
274
+ if ( ! isset( $custom_urls[ $current_language ][ $slug_in_work ] ) ) {
275
+ return;
276
+ }
277
+
278
+ $_SERVER['REQUEST_URI'] = str_replace(
279
+ '/' . $current_language . '/',
280
+ '/',
281
+ str_replace( $slug_in_work, $custom_urls[ $current_language ][ $slug_in_work ], $_SERVER['REQUEST_URI'] ) //phpcs:ignore
282
+ );
283
  }
284
 
285
  /**
318
  public function weglot_treat_page( $content ) {
319
  $this->current_language = $this->request_url_services->get_current_language(); // Need to reset
320
  $allowed = $this->option_services->get_option( 'allowed' );
321
+ // Choose type translate
322
+ $type = ( $this->is_json( $content ) ) ? 'json' : 'html';
323
+ $type = apply_filters( 'weglot_type_treat_page', $type );
324
 
325
  if ( ! $allowed ) {
326
  $content = $this->weglot_render_dom( $content );
327
+ if ( 'json' === $type || wp_doing_ajax() ) {
328
+ return $content;
329
+ }
330
+
331
  return $content . '<!--Not allowed-->';
332
  }
333
 
340
 
341
  $parser = $this->parser_services->get_parser();
342
 
 
 
 
 
343
  try {
344
  switch ( $type ) {
345
  case 'json':
346
+ $json = \json_decode( $content, true );
347
  $content = $this->translate_array( $json );
348
+ $content = $this->replace_link_array( $content );
349
  $content = apply_filters( 'weglot_json_treat_page', $content );
350
 
351
  return wp_json_encode( $content );
372
 
373
  }
374
  } catch ( ApiError $e ) {
375
+ if( $type !== 'json'){
376
+ $content .= '<!--Weglot error API : ' . $this->remove_comments( $e->getMessage() ) . '-->';
377
+ }
378
  if ( strpos( $e->getMessage(), 'NMC' ) !== false ) {
379
  $this->option_services->set_option_by_key( 'allowed', false );
380
  }
381
  return $content;
382
  } catch ( \Exception $e ) {
383
+ if ( $type !== 'json') {
384
+ $content .= '<!--Weglot error : ' . $this->remove_comments( $e->getMessage() ) . '-->';
385
+ }
386
  return $content;
387
  }
388
  }
404
  * @return boolean
405
  */
406
  public function is_json( $string ) {
407
+ return is_string( $string ) && is_array( \json_decode( $string, true ) ) && ( JSON_ERROR_NONE === \json_last_error() ) ? true : false;
408
  }
409
 
410
  /**
427
  $is_fullname = $options['is_fullname'];
428
  $with_name = $options['with_name'];
429
 
430
+ $url = $this->request_url_services->get_weglot_url();
431
+ // Custom URLS
432
+ $request_without_language = array_filter( explode( '/', $url->getPath() ), 'strlen' );
433
+ $index_entries = count( $request_without_language );
434
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
435
+ global $post;
436
+
437
  foreach ( $languages_configured as $language ) {
438
  $shortcode_title = sprintf( '\[weglot_menu_title-%s\]', $language->getIso639() );
439
  $shortcode_title_without_bracket = sprintf( 'weglot_menu_title-%s', $language->getIso639() );
443
  $shortcode_url_html = str_replace( '\[', '%5B', $shortcode_url );
444
  $shortcode_url_html = str_replace( '\]', '%5D', $shortcode_url_html );
445
 
446
+
447
 
448
  $name = '';
449
  if ( $with_name ) {
459
  $link_menu .= '?no_lredirect=true';
460
  }
461
 
462
+ if ( isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) ) {
463
+ $slug_in_work = $request_without_language[ $index_entries ];
464
+ $key_code = $language->getIso639();
465
+
466
+ // Search from original slug
467
+ $key_slug = false;
468
+ if ( isset( $custom_urls[ $key_code ] ) && $post ) {
469
+ $key_slug = array_search( $post->post_name, $custom_urls[ $key_code ] );
470
+ }
471
+
472
+ if ( false !== $key_slug ) {
473
+ $link_menu = str_replace( $slug_in_work, $key_slug, $link_menu );
474
+ } else {
475
+ $link_menu = str_replace( $slug_in_work, $post->post_name, $link_menu );
476
+ }
477
+ }
478
+
479
  // Compatibility Menu HTTPS if not work. Since 2.0.6
480
  if (
481
  (
487
  $link_menu = str_replace( 'http', 'https', $link_menu );
488
  }
489
 
490
+
491
  $dom = preg_replace( '#' . $shortcode_url . '#i', $link_menu, $dom );
492
  $dom = preg_replace( '#' . $shortcode_url_html . '#i', $link_menu, $dom );
493
  }
src/helpers/class-helper-json-inline-weglot.php CHANGED
@@ -19,7 +19,7 @@ abstract class Helper_Json_Inline_Weglot {
19
  */
20
  public static function format_for_api( $string ) {
21
  $string = '"' . $string . '"';
22
- return json_decode( str_replace( '\\/', '/', str_replace( '\\\\', '\\', $string ) ) );
23
  }
24
 
25
  /**
@@ -28,7 +28,7 @@ abstract class Helper_Json_Inline_Weglot {
28
  * @return string
29
  */
30
  public static function unformat_from_api( $string ) {
31
- $string = str_replace( '"', '', str_replace( '/', '\\\\/', str_replace( '\\u', '\\\\u', json_encode( $string ) ) ) ); //phpcs:ignore
32
  return $string;
33
  }
34
  }
19
  */
20
  public static function format_for_api( $string ) {
21
  $string = '"' . $string . '"';
22
+ return \json_decode( str_replace( '\\/', '/', str_replace( '\\\\', '\\', $string ) ) );
23
  }
24
 
25
  /**
28
  * @return string
29
  */
30
  public static function unformat_from_api( $string ) {
31
+ $string = str_replace( '"', '', str_replace( '/', '\\\\/', str_replace( '\\u', '\\\\u', \json_encode( $string ) ) ) ); //phpcs:ignore
32
  return $string;
33
  }
34
  }
src/helpers/class-helper-post-meta-weglot.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Helpers;
4
+
5
+ // Exit if accessed directly.
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
+ /**
11
+ * @since 2.1.0
12
+ */
13
+ class Helper_Post_Meta_Weglot {
14
+
15
+ /**
16
+ * @var string
17
+ */
18
+ const POST_NAME_WEGLOT = 'post_name_weglot';
19
+ }
src/services/class-button-service-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
 
10
  /**
11
  * Button services
@@ -77,8 +78,10 @@ class Button_Service_Weglot {
77
  $name = ( $is_fullname ) ? $current_language_entry->getLocalName() : strtoupper( $current_language_entry->getIso639() );
78
  }
79
 
80
- $uniqId = 'wg' . uniqid( strtotime( 'now' ) ) . rand( 1, 1000 );
81
- $button_html .= sprintf( '<input id="%s" class="weglot_choice" type="checkbox" name="menu"/><label for="%s" class="wgcurrent wg-li %s" data-code-language="%s"><span>%s</span></label>', $uniqId, $uniqId, $flag_class . $current_language, $current_language_entry->getIso639(), $name );
 
 
82
 
83
  $button_html .= '<ul>';
84
 
@@ -105,10 +108,33 @@ class Button_Service_Weglot {
105
 
106
  $button_html .= sprintf( '<li class="wg-li %s" data-code-language="%s">', $flag_class . $key_code, $key_code );
107
 
108
- $link_button = apply_filters( 'weglot_link_language', $weglot_url->getForLanguage( $key_code ), $key_code );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
- $link_button = preg_replace('#\?no_lredirect=true$#', '', $link_button); // Remove ending "?no_lredirect=true"
111
- if ( weglot_has_auto_redirect() && strpos( $link_button, 'no_lredirect' ) === false && ( is_home() || is_front_page() ) && $key_code === $original_language) {
112
  $link_button .= '?no_lredirect=true';
113
  }
114
 
6
  exit;
7
  }
8
 
9
+ use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
10
 
11
  /**
12
  * Button services
78
  $name = ( $is_fullname ) ? $current_language_entry->getLocalName() : strtoupper( $current_language_entry->getIso639() );
79
  }
80
 
81
+ global $post;
82
+
83
+ $uniq_id = 'wg' . uniqid( strtotime( 'now' ) ) . rand( 1, 1000 );
84
+ $button_html .= sprintf( '<input id="%s" class="weglot_choice" type="checkbox" name="menu"/><label for="%s" class="wgcurrent wg-li %s" data-code-language="%s"><span>%s</span></label>', $uniq_id, $uniq_id, $flag_class . $current_language, $current_language_entry->getIso639(), $name );
85
 
86
  $button_html .= '<ul>';
87
 
108
 
109
  $button_html .= sprintf( '<li class="wg-li %s" data-code-language="%s">', $flag_class . $key_code, $key_code );
110
 
111
+ $url_lang = $weglot_url->getForLanguage( $key_code );
112
+
113
+ // Custom URLS
114
+ $request_without_language = array_filter( explode( '/', $weglot_url->getPath() ), 'strlen' );
115
+ $index_entries = count( $request_without_language );
116
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
117
+
118
+ if ( isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) ) {
119
+ $slug_in_work = $request_without_language[ $index_entries ];
120
+
121
+ // Search from original slug
122
+ $key_slug = false;
123
+ if ( isset( $custom_urls[ $key_code ] ) && $post ) {
124
+ $key_slug = array_search( $post->post_name, $custom_urls[ $key_code ] );
125
+ }
126
+
127
+ if ( false !== $key_slug ) {
128
+ $url_lang = str_replace( $slug_in_work, $key_slug, $url_lang );
129
+ } else {
130
+ $url_lang = str_replace( $slug_in_work, $post->post_name, $url_lang );
131
+ }
132
+ }
133
+
134
+ $link_button = apply_filters( 'weglot_link_language', $url_lang, $key_code );
135
 
136
+ $link_button = preg_replace( '#\?no_lredirect=true$#', '', $link_button ); // Remove ending "?no_lredirect=true"
137
+ if ( weglot_has_auto_redirect() && strpos( $link_button, 'no_lredirect' ) === false && ( is_home() || is_front_page() ) && $key_code === $original_language ) {
138
  $link_button .= '?no_lredirect=true';
139
  }
140
 
src/services/class-option-service-weglot.php CHANGED
@@ -35,6 +35,8 @@ class Option_Service_Weglot {
35
  'show_box_first_settings' => false,
36
  'rtl_ltr_style' => '',
37
  'allowed' => true,
 
 
38
  ];
39
 
40
  /**
35
  'show_box_first_settings' => false,
36
  'rtl_ltr_style' => '',
37
  'allowed' => true,
38
+ 'custom_urls' => [],
39
+ 'flag_css' => ''
40
  ];
41
 
42
  /**
src/services/class-replace-link-service-weglot.php CHANGED
@@ -15,7 +15,8 @@ class Replace_Link_Service_Weglot {
15
  * @since 2.0
16
  */
17
  public function __construct() {
18
- $this->multisite_service = weglot_get_service( 'Multisite_Service_Weglot' );
 
19
  }
20
 
21
  /**
@@ -26,6 +27,7 @@ class Replace_Link_Service_Weglot {
26
  */
27
  public function replace_url( $url ) {
28
  $current_and_original = weglot_get_current_and_original_language();
 
29
 
30
  $parsed_url = wp_parse_url( $url );
31
  $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
@@ -43,6 +45,17 @@ class Replace_Link_Service_Weglot {
43
  if ( $current_and_original['current'] === $current_and_original['original'] ) {
44
  return $url;
45
  } else {
 
 
 
 
 
 
 
 
 
 
 
46
  $url_translated = ( strlen( $path ) > 2 && substr( $path, 0, 4 ) === "/$current_language/" ) ?
47
  "$scheme$user$pass$host$port$path$query$fragment" : "$scheme$user$pass$host$port/$current_language$path$query$fragment";
48
 
15
  * @since 2.0
16
  */
17
  public function __construct() {
18
+ $this->multisite_service = weglot_get_service( 'Multisite_Service_Weglot' );
19
+ $this->option_service = weglot_get_service( 'Option_Service_Weglot' );
20
  }
21
 
22
  /**
27
  */
28
  public function replace_url( $url ) {
29
  $current_and_original = weglot_get_current_and_original_language();
30
+ $custom_urls = $this->option_service->get_option( 'custom_urls' );
31
 
32
  $parsed_url = wp_parse_url( $url );
33
  $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
45
  if ( $current_and_original['current'] === $current_and_original['original'] ) {
46
  return $url;
47
  } else {
48
+ $request_without_language = array_filter( explode( '/', $path ), 'strlen' );
49
+ $index_entries = count( $request_without_language );
50
+
51
+ if ( isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) && isset( $custom_urls[ $current_language ] ) ) {
52
+ $slug_in_work = $request_without_language[ $index_entries ];
53
+ $key_slug = array_search( $slug_in_work, $custom_urls[ $current_language ] ); //phpcs:ignore
54
+ if ( false !== $key_slug && ! empty( $key_slug ) ) {
55
+ $path = str_replace( $slug_in_work, $key_slug, $path );
56
+ }
57
+ }
58
+
59
  $url_translated = ( strlen( $path ) > 2 && substr( $path, 0, 4 ) === "/$current_language/" ) ?
60
  "$scheme$user$pass$host$port$path$query$fragment" : "$scheme$user$pass$host$port/$current_language$path$query$fragment";
61
 
src/services/class-replace-url-service-weglot.php CHANGED
@@ -47,7 +47,7 @@ class Replace_Url_Service_Weglot {
47
  continue;
48
  }
49
 
50
- if ( self::check_link( $current_url, $sometags, $sometags2 ) ) {
51
  $function_name = 'replace_' . $type;
52
 
53
  $translated_page = $this->replace_link_service->$function_name(
47
  continue;
48
  }
49
 
50
+ if ( $this->check_link( $current_url, $sometags, $sometags2 ) ) {
51
  $function_name = 'replace_' . $type;
52
 
53
  $translated_page = $this->replace_link_service->$function_name(
src/services/class-request-url-service-weglot.php CHANGED
@@ -113,7 +113,7 @@ class Request_Url_Service_Weglot {
113
  * @return boolean
114
  */
115
  public function is_translatable_url() {
116
- return $this->get_weglot_url()->isTranslable();
117
  }
118
 
119
 
@@ -183,8 +183,8 @@ class Request_Url_Service_Weglot {
183
  * @return boolean
184
  */
185
  public function is_eligible_url( $url ) {
186
- $url = urldecode( $this->url_to_relative( $url ) );
187
 
 
188
  //Format exclude URL
189
  $exclude_urls_option = weglot_get_exclude_urls();
190
 
@@ -212,6 +212,16 @@ class Request_Url_Service_Weglot {
212
  $list_regex[] = $this->amp_services->get_regex();
213
  }
214
 
 
 
 
 
 
 
 
 
 
 
215
  foreach ( $list_regex as $regex ) {
216
  $str = $this->escape_slash( $regex );
217
  $prepare_regex = sprintf( '/%s/', $str );
@@ -219,6 +229,10 @@ class Request_Url_Service_Weglot {
219
  if ( preg_match( $prepare_regex, $url ) === 1 ) {
220
  return apply_filters( 'weglot_is_eligible_url', false, $url );
221
  }
 
 
 
 
222
  }
223
 
224
  return apply_filters( 'weglot_is_eligible_url', true, $url );
113
  * @return boolean
114
  */
115
  public function is_translatable_url() {
116
+ return $this->get_weglot_url()->isTranslable() && $this->is_eligible_url( $this->get_full_url() );
117
  }
118
 
119
 
183
  * @return boolean
184
  */
185
  public function is_eligible_url( $url ) {
 
186
 
187
+ $url = urldecode( $this->url_to_relative( $url ) );
188
  //Format exclude URL
189
  $exclude_urls_option = weglot_get_exclude_urls();
190
 
212
  $list_regex[] = $this->amp_services->get_regex();
213
  }
214
 
215
+ $path_without_language = array_filter( explode( '/', $url ), 'strlen' );
216
+ $index_entries = count( $path_without_language );
217
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
218
+ $current_language = $this->get_current_language();
219
+
220
+ $url_path_custom = null;
221
+ if( ! empty( $custom_urls ) && isset( $custom_urls[ $current_language ] ) && isset( $path_without_language[$index_entries] ) && isset( $custom_urls[ $current_language ][ $path_without_language[$index_entries] ] ) ){
222
+ $url_path_custom = '/' . $custom_urls[ $current_language ][ $path_without_language[$index_entries] ] . '/';
223
+ }
224
+
225
  foreach ( $list_regex as $regex ) {
226
  $str = $this->escape_slash( $regex );
227
  $prepare_regex = sprintf( '/%s/', $str );
229
  if ( preg_match( $prepare_regex, $url ) === 1 ) {
230
  return apply_filters( 'weglot_is_eligible_url', false, $url );
231
  }
232
+
233
+ if( null !== $url_path_custom && preg_match( $prepare_regex, $url_path_custom ) === 1 ){
234
+ return apply_filters( 'weglot_is_eligible_url', false, $url );
235
+ }
236
  }
237
 
238
  return apply_filters( 'weglot_is_eligible_url', true, $url );
src/services/class-user-api-service-weglot.php CHANGED
@@ -44,14 +44,14 @@ class User_Api_Service_Weglot {
44
  }
45
 
46
  if ( null === $api_key ) {
47
- $api_key = weglot_get_api_key();
48
  }
49
 
50
  try {
51
  $results = $this->do_request( self::API_BASE_OLD . 'user-info?api_key=' . $api_key, null );
52
- $json = json_decode( $results, true );
53
- if ( json_last_error() !== JSON_ERROR_NONE ) {
54
- throw new \Exception( 'Unknown error with Weglot Api (0001) : ' . json_last_error() );
55
  }
56
 
57
  if ( isset( $json['succeeded'] ) && ( 0 === $json['succeeded'] || 1 === $json['succeeded'] ) ) {
@@ -109,7 +109,7 @@ class User_Api_Service_Weglot {
109
  public function do_request( $url, $parameters ) {
110
  if ( $parameters ) {
111
  $payload = json_encode( $parameters ); //phpcs:ignore
112
- if ( json_last_error() === JSON_ERROR_NONE ) {
113
  $response = wp_remote_post(
114
  $url,
115
  array(
@@ -126,7 +126,7 @@ class User_Api_Service_Weglot {
126
  )
127
  );
128
  } else {
129
- throw new \Exception( 'Cannot json encode parameters: ' . json_last_error() );
130
  }
131
  } else {
132
  $response = wp_remote_get( //phpcs:ignore
44
  }
45
 
46
  if ( null === $api_key ) {
47
+ $api_key = \weglot_get_api_key();
48
  }
49
 
50
  try {
51
  $results = $this->do_request( self::API_BASE_OLD . 'user-info?api_key=' . $api_key, null );
52
+ $json = \json_decode( $results, true );
53
+ if ( \json_last_error() !== JSON_ERROR_NONE ) {
54
+ throw new \Exception( 'Unknown error with Weglot Api (0001) : ' . \json_last_error() );
55
  }
56
 
57
  if ( isset( $json['succeeded'] ) && ( 0 === $json['succeeded'] || 1 === $json['succeeded'] ) ) {
109
  public function do_request( $url, $parameters ) {
110
  if ( $parameters ) {
111
  $payload = json_encode( $parameters ); //phpcs:ignore
112
+ if ( \json_last_error() === JSON_ERROR_NONE ) {
113
  $response = wp_remote_post(
114
  $url,
115
  array(
126
  )
127
  );
128
  } else {
129
+ throw new \Exception( 'Cannot json encode parameters: ' . \json_last_error() );
130
  }
131
  } else {
132
  $response = wp_remote_get( //phpcs:ignore
src/third/woocommerce/class-wc-translate-weglot.php CHANGED
@@ -62,6 +62,10 @@ class WC_Translate_Weglot {
62
 
63
  preg_match_all( '#(label|placeholder)\\\":\\\"(.*?)\\\"#', $match[1], $all );
64
 
 
 
 
 
65
  $object = $this->translate_entries( $all[2] );
66
 
67
  foreach ( $object->getInputWords() as $key => $input_word ) {
@@ -90,6 +94,10 @@ class WC_Translate_Weglot {
90
 
91
  preg_match_all( '#i18n_view_cart\":\"(.*?)\"#', $match[1], $all );
92
 
 
 
 
 
93
  $object = $this->translate_entries( $all[1] );
94
 
95
  foreach ( $object->getInputWords() as $key => $input_word ) {
62
 
63
  preg_match_all( '#(label|placeholder)\\\":\\\"(.*?)\\\"#', $match[1], $all );
64
 
65
+ if ( empty( $all[2] ) ) {
66
+ return $content;
67
+ }
68
+
69
  $object = $this->translate_entries( $all[2] );
70
 
71
  foreach ( $object->getInputWords() as $key => $input_word ) {
94
 
95
  preg_match_all( '#i18n_view_cart\":\"(.*?)\"#', $match[1], $all );
96
 
97
+ if ( empty( $all[1] ) ) {
98
+ return $content;
99
+ }
100
+
101
  $object = $this->translate_entries( $all[1] );
102
 
103
  foreach ( $object->getInputWords() as $key => $input_word ) {
templates/admin/metaboxes/url-translate.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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($pagenow === 'post-new.php'){
13
+ esc_html_e( 'You must first create the page a first time before you can benefit from custom URLs', 'weglot' );
14
+ }
15
+ else{
16
+
17
+ $languages_available = $this->language_services->get_languages_configured();
18
+ $original_language = weglot_get_original_language();
19
+ list( $permalink ) = get_sample_permalink( $post->ID );
20
+ $display_link = str_replace( array( '%pagename%', '%postname%', home_url() ), '', $permalink );
21
+ $display_link = implode( '/', array_filter( explode( '/', $display_link ), 'strlen' ) );
22
+
23
+ if ( ! empty( $display_link ) && '/' !== $display_link[ strlen( $display_link ) - 1 ] ) {
24
+ $display_link .= '/';
25
+ }
26
+
27
+ ?>
28
+ <input type="hidden" id="weglot_post_id" data-id="<?php echo esc_attr( $post->ID ); ?>" />
29
+ <?php
30
+ foreach ( $languages_available as $language ) {
31
+ $code = $language->getIso639();
32
+ if ( $code === $original_language ) {
33
+ continue;
34
+ }
35
+
36
+ $post_name_weglot = $post->post_name;
37
+ $post_name_input = '';
38
+ if ( isset( $this->custom_urls[ $code ] ) ) {
39
+ $post_name_weglot = array_search( $post_name_weglot, $this->custom_urls[ $code ] );
40
+ if ( false === $post_name_weglot || empty( $post_name_weglot ) ) {
41
+ $post_name_weglot = $post->post_name;
42
+ } else {
43
+ $post_name_input = $post_name_weglot;
44
+ }
45
+ } ?>
46
+ <label for="lang-<?php echo esc_attr( $code ); ?>">
47
+ <strong><?php echo esc_attr( $language->getLocalName() ); ?></strong>
48
+ </label>
49
+ <div class="weglot_custom_url">
50
+ <p class="weglot_custom_url--text_link">
51
+ <?php echo esc_url( home_url() ); ?>/<?php echo esc_attr( $code ); ?>/<?php echo esc_attr( $display_link ); ?><span id="text-edit-<?php echo esc_attr( $code ); ?>"><?php echo esc_attr( $post_name_weglot ); ?></span>
52
+ <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;"/>
53
+
54
+ <button type="button" class="button button-small button-weglot-lang" data-lang="<?php echo esc_attr( $code ); ?>" aria-label="Edit permalink weglot"><?php esc_html_e( 'Edit', 'weglot' ); ?></button>
55
+
56
+ <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>
57
+ </p>
58
+ <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>
59
+ <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 $post_name_weglot ; ?>" class="weglot_reset">
60
+ <?php esc_html_e( 'Reset custom url', 'weglot' ); ?>
61
+ </a>
62
+ </div>
63
+
64
+ <?php
65
+ }
66
+ }
67
+
templates/admin/pages/tabs/status.php CHANGED
@@ -25,6 +25,8 @@ if ( version_compare( phpversion(), '5.4', '<' ) ) {
25
  $php_min_54 = false;
26
  }
27
 
 
 
28
  ?>
29
 
30
 
@@ -130,12 +132,17 @@ if ( version_compare( phpversion(), '5.4', '<' ) ) {
130
  </tr>
131
  <tr>
132
  <td><?php esc_html_e( 'Exclude URLs', 'weglot' ); ?></td>
133
- <td><?php echo esc_attr( get_option( 'exclude_url' ) ); ?></td>
134
  </tr>
135
  <tr>
136
  <td><?php esc_html_e( 'Exclude Blocks', 'weglot' ); ?></td>
137
- <td><?php echo esc_attr( get_option( 'exclude_blocks' ) ); ?></td>
138
  </tr>
139
  </tbody>
140
  </table>
 
 
 
 
 
141
  </div>
25
  $php_min_54 = false;
26
  }
27
 
28
+ $options = weglot_get_options();
29
+
30
  ?>
31
 
32
 
132
  </tr>
133
  <tr>
134
  <td><?php esc_html_e( 'Exclude URLs', 'weglot' ); ?></td>
135
+ <td><?php echo esc_attr( implode( $options[ 'exclude_urls' ], ' - ' ) ); ?></td>
136
  </tr>
137
  <tr>
138
  <td><?php esc_html_e( 'Exclude Blocks', 'weglot' ); ?></td>
139
+ <td><?php echo esc_attr( implode( $options[ 'exclude_blocks' ], ' - ' ) ); ?></td>
140
  </tr>
141
  </tbody>
142
  </table>
143
+ <br />
144
+ <div class="widefat">
145
+ <h2><?php esc_html_e( 'Custom URLS', 'weglot'); ?></h2>
146
+ <?php var_export($options['custom_urls']); ?>
147
+ </div>
148
  </div>
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit91145ad7da755053e6c2f4a1f34084b8::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInitd9fdaf5d980da38301cf7e67cf96ca17::getLoader();
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit91145ad7da755053e6c2f4a1f34084b8
6
  {
7
  private static $loader;
8
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInit91145ad7da755053e6c2f4a1f34084b8
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInit91145ad7da755053e6c2f4a1f34084b8', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit91145ad7da755053e6c2f4a1f34084b8', '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\ComposerStaticInit91145ad7da755053e6c2f4a1f34084b8::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInit91145ad7da755053e6c2f4a1f34084b8
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
- $includeFiles = Composer\Autoload\ComposerStaticInit91145ad7da755053e6c2f4a1f34084b8::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
- composerRequire91145ad7da755053e6c2f4a1f34084b8($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
- function composerRequire91145ad7da755053e6c2f4a1f34084b8($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 ComposerAutoloaderInitd9fdaf5d980da38301cf7e67cf96ca17
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInitd9fdaf5d980da38301cf7e67cf96ca17', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInitd9fdaf5d980da38301cf7e67cf96ca17', '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\ComposerStaticInitd9fdaf5d980da38301cf7e67cf96ca17::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
+ $includeFiles = Composer\Autoload\ComposerStaticInitd9fdaf5d980da38301cf7e67cf96ca17::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
+ composerRequired9fdaf5d980da38301cf7e67cf96ca17($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
+ function composerRequired9fdaf5d980da38301cf7e67cf96ca17($fileIdentifier, $file)
64
  {
65
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit91145ad7da755053e6c2f4a1f34084b8
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
@@ -45,9 +45,9 @@ class ComposerStaticInit91145ad7da755053e6c2f4a1f34084b8
45
  public static function getInitializer(ClassLoader $loader)
46
  {
47
  return \Closure::bind(function () use ($loader) {
48
- $loader->prefixLengthsPsr4 = ComposerStaticInit91145ad7da755053e6c2f4a1f34084b8::$prefixLengthsPsr4;
49
- $loader->prefixDirsPsr4 = ComposerStaticInit91145ad7da755053e6c2f4a1f34084b8::$prefixDirsPsr4;
50
- $loader->prefixesPsr0 = ComposerStaticInit91145ad7da755053e6c2f4a1f34084b8::$prefixesPsr0;
51
 
52
  }, null, ClassLoader::class);
53
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInitd9fdaf5d980da38301cf7e67cf96ca17
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
45
  public static function getInitializer(ClassLoader $loader)
46
  {
47
  return \Closure::bind(function () use ($loader) {
48
+ $loader->prefixLengthsPsr4 = ComposerStaticInitd9fdaf5d980da38301cf7e67cf96ca17::$prefixLengthsPsr4;
49
+ $loader->prefixDirsPsr4 = ComposerStaticInitd9fdaf5d980da38301cf7e67cf96ca17::$prefixDirsPsr4;
50
+ $loader->prefixesPsr0 = ComposerStaticInitd9fdaf5d980da38301cf7e67cf96ca17::$prefixesPsr0;
51
 
52
  }, null, ClassLoader::class);
53
  }
vendor/composer/installed.json CHANGED
@@ -96,17 +96,17 @@
96
  },
97
  {
98
  "name": "weglot/weglot-php",
99
- "version": "0.5.11",
100
- "version_normalized": "0.5.11.0",
101
  "source": {
102
  "type": "git",
103
  "url": "https://github.com/weglot/weglot-php.git",
104
- "reference": "7f2df77f2eb195f8554606555732bb8836f04407"
105
  },
106
  "dist": {
107
  "type": "zip",
108
- "url": "https://api.github.com/repos/weglot/weglot-php/zipball/7f2df77f2eb195f8554606555732bb8836f04407",
109
- "reference": "7f2df77f2eb195f8554606555732bb8836f04407",
110
  "shasum": ""
111
  },
112
  "require": {
@@ -118,7 +118,7 @@
118
  "codeception/codeception": "^2.4",
119
  "vlucas/phpdotenv": "^2.4"
120
  },
121
- "time": "2018-07-31T15:23:07+00:00",
122
  "type": "library",
123
  "installation-source": "dist",
124
  "autoload": {
96
  },
97
  {
98
  "name": "weglot/weglot-php",
99
+ "version": "0.5.12",
100
+ "version_normalized": "0.5.12.0",
101
  "source": {
102
  "type": "git",
103
  "url": "https://github.com/weglot/weglot-php.git",
104
+ "reference": "d85ec3719d658c893e568dec90fa01f805b70cd5"
105
  },
106
  "dist": {
107
  "type": "zip",
108
+ "url": "https://api.github.com/repos/weglot/weglot-php/zipball/d85ec3719d658c893e568dec90fa01f805b70cd5",
109
+ "reference": "d85ec3719d658c893e568dec90fa01f805b70cd5",
110
  "shasum": ""
111
  },
112
  "require": {
118
  "codeception/codeception": "^2.4",
119
  "vlucas/phpdotenv": "^2.4"
120
  },
121
+ "time": "2018-09-19T12:33:26+00:00",
122
  "type": "library",
123
  "installation-source": "dist",
124
  "autoload": {
vendor/weglot/weglot-php/CHANGELOG.md CHANGED
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
 
7
  ## [Unreleased]
8
 
 
 
 
9
  ## [0.5.11] - 2018-07-31
10
  ### Changed
11
  Better API errors management
6
 
7
  ## [Unreleased]
8
 
9
+ ## [0.5.12] - 2018-09-19
10
+ Add escape property on dom checker
11
+
12
  ## [0.5.11] - 2018-07-31
13
  ### Changed
14
  Better API errors management
vendor/weglot/weglot-php/src/Parser/Check/Dom/AbstractDomChecker.php CHANGED
@@ -34,6 +34,13 @@ abstract class AbstractDomChecker
34
  */
35
  const WORD_TYPE = WordType::TEXT;
36
 
 
 
 
 
 
 
 
37
  /**
38
  * @var simple_html_dom_node
39
  */
34
  */
35
  const WORD_TYPE = WordType::TEXT;
36
 
37
+ /**
38
+ * Need to escape DOM attribute
39
+ *
40
+ * @var bool
41
+ */
42
+ const ESCAPE_SPECIAL_CHAR = false;
43
+
44
  /**
45
  * @var simple_html_dom_node
46
  */
vendor/weglot/weglot-php/src/Parser/Check/Dom/ImageAlt.php CHANGED
@@ -24,4 +24,9 @@ class ImageAlt extends AbstractDomChecker
24
  * {@inheritdoc}
25
  */
26
  const WORD_TYPE = WordType::IMG_ALT;
 
 
 
 
 
27
  }
24
  * {@inheritdoc}
25
  */
26
  const WORD_TYPE = WordType::IMG_ALT;
27
+
28
+ /**
29
+ * {@inheritdoc}
30
+ */
31
+ const ESCAPE_SPECIAL_CHAR =true;
32
  }
vendor/weglot/weglot-php/src/Parser/Check/Dom/LinkDataTitle.php CHANGED
@@ -24,4 +24,9 @@ class LinkDataTitle extends AbstractDomChecker
24
  * {@inheritdoc}
25
  */
26
  const WORD_TYPE = WordType::TEXT;
 
 
 
 
 
27
  }
24
  * {@inheritdoc}
25
  */
26
  const WORD_TYPE = WordType::TEXT;
27
+
28
+ /**
29
+ * {@inheritdoc}
30
+ */
31
+ const ESCAPE_SPECIAL_CHAR =true;
32
  }
vendor/weglot/weglot-php/src/Parser/Check/Dom/LinkTitle.php CHANGED
@@ -24,4 +24,9 @@ class LinkTitle extends AbstractDomChecker
24
  * {@inheritdoc}
25
  */
26
  const WORD_TYPE = WordType::TEXT;
 
 
 
 
 
27
  }
24
  * {@inheritdoc}
25
  */
26
  const WORD_TYPE = WordType::TEXT;
27
+
28
+ /**
29
+ * {@inheritdoc}
30
+ */
31
+ const ESCAPE_SPECIAL_CHAR =true;
32
  }
vendor/weglot/weglot-php/src/Parser/Check/Dom/MetaContent.php CHANGED
@@ -26,6 +26,11 @@ class MetaContent extends AbstractDomChecker
26
  */
27
  const WORD_TYPE = WordType::META_CONTENT;
28
 
 
 
 
 
 
29
  /**
30
  * {@inheritdoc}
31
  */
26
  */
27
  const WORD_TYPE = WordType::META_CONTENT;
28
 
29
+ /**
30
+ * {@inheritdoc}
31
+ */
32
+ const ESCAPE_SPECIAL_CHAR = true;
33
+
34
  /**
35
  * {@inheritdoc}
36
  */
vendor/weglot/weglot-php/src/Parser/Formatter/DomFormatter.php CHANGED
@@ -37,7 +37,7 @@ class DomFormatter extends AbstractFormatter
37
  protected function metaContent(array $details, $translated) {
38
  $property = $details['property'];
39
 
40
- if ($details['class'] === '\Weglot\Parser\Check\Dom\MetaContent') {
41
  $details['node']->$property = htmlspecialchars($translated);
42
  } else {
43
  $details['node']->$property = $translated;
37
  protected function metaContent(array $details, $translated) {
38
  $property = $details['property'];
39
 
40
+ if ($details['class']::ESCAPE_SPECIAL_CHAR) {
41
  $details['node']->$property = htmlspecialchars($translated);
42
  } else {
43
  $details['node']->$property = $translated;
webpack.config.js CHANGED
@@ -8,9 +8,10 @@ module.exports = {
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"
14
  },
15
  output: {
16
  path: __dirname + "/dist",
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"
15
  },
16
  output: {
17
  path: __dirname + "/dist",
weglot-functions.php CHANGED
@@ -22,7 +22,7 @@ function weglot_get_service( $service ) {
22
  * @return array
23
  */
24
  function weglot_get_options() {
25
- return Context_Weglot::weglot_get_context()->get_service( '' )->get_options();
26
  }
27
 
28
  /**
22
  * @return array
23
  */
24
  function weglot_get_options() {
25
+ return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_options();
26
  }
27
 
28
  /**
weglot.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * @version 2.0.7
4
  */
5
 
6
  /*
@@ -11,7 +11,7 @@ Author: Weglot Translate team
11
  Author URI: https://weglot.com/
12
  Text Domain: weglot
13
  Domain Path: /languages/
14
- Version: 2.0.7
15
  */
16
 
17
  /**
@@ -27,7 +27,7 @@ if ( ! defined('ABSPATH')) {
27
  define('WEGLOT_NAME', 'Weglot');
28
  define('WEGLOT_SLUG', 'weglot-translate');
29
  define('WEGLOT_OPTION_GROUP', 'group-weglot-translate');
30
- define('WEGLOT_VERSION', '2.0.7');
31
  define('WEGLOT_PHP_MIN', '5.4');
32
  define('WEGLOT_BNAME', plugin_basename(__FILE__));
33
  define('WEGLOT_DIR', __DIR__ );
@@ -41,6 +41,7 @@ define('WEGLOT_LIB_PARSER', '1');
41
 
42
  define('WEGLOT_TEMPLATES', WEGLOT_DIR . '/templates');
43
  define('WEGLOT_TEMPLATES_ADMIN', WEGLOT_TEMPLATES . '/admin');
 
44
  define('WEGLOT_TEMPLATES_ADMIN_NOTICES', WEGLOT_TEMPLATES_ADMIN . '/notices');
45
  define('WEGLOT_TEMPLATES_ADMIN_PAGES', WEGLOT_TEMPLATES_ADMIN . '/pages');
46
 
1
  <?php
2
  /**
3
+ * @version 2.1.0
4
  */
5
 
6
  /*
11
  Author URI: https://weglot.com/
12
  Text Domain: weglot
13
  Domain Path: /languages/
14
+ Version: 2.1.0
15
  */
16
 
17
  /**
27
  define('WEGLOT_NAME', 'Weglot');
28
  define('WEGLOT_SLUG', 'weglot-translate');
29
  define('WEGLOT_OPTION_GROUP', 'group-weglot-translate');
30
+ define('WEGLOT_VERSION', '2.1.0');
31
  define('WEGLOT_PHP_MIN', '5.4');
32
  define('WEGLOT_BNAME', plugin_basename(__FILE__));
33
  define('WEGLOT_DIR', __DIR__ );
41
 
42
  define('WEGLOT_TEMPLATES', WEGLOT_DIR . '/templates');
43
  define('WEGLOT_TEMPLATES_ADMIN', WEGLOT_TEMPLATES . '/admin');
44
+ define('WEGLOT_TEMPLATES_ADMIN_METABOXES', WEGLOT_TEMPLATES_ADMIN . '/metaboxes');
45
  define('WEGLOT_TEMPLATES_ADMIN_NOTICES', WEGLOT_TEMPLATES_ADMIN . '/notices');
46
  define('WEGLOT_TEMPLATES_ADMIN_PAGES', WEGLOT_TEMPLATES_ADMIN . '/pages');
47