Version Description
(05/12/2018) = * Bugfix : Custom URL on archive page * Bugfix : Prevent error on translate AJAX * Bugfix : Href lang on custom URLs * Improve code quality * Compatibility SEOPress : exclude sitemap * Improve private languages * Add two DOM checkers
Download this release
Release Info
Developer | remyb92 |
Plugin | Weglot Translate – Translate your WP website |
Version | 2.3.0 |
Comparing to | |
See all releases |
Code changes from version 2.2.2 to 2.3.0
- app/javascripts/index.js +2 -0
- app/javascripts/settings/admin-private-mode.js +30 -0
- app/styles/admin.scss +27 -0
- bootstrap.php +8 -3
- composer.json +2 -1
- dist/admin-js.js +1 -1
- dist/css/admin-css.css +25 -0
- readme.txt +11 -2
- src/actions/admin/class-admin-enqueue-weglot.php +3 -0
- src/actions/admin/class-customize-menu-weglot.php +12 -11
- src/actions/admin/class-metabox-url-translate-weglot.php +21 -1
- src/actions/admin/class-options-weglot.php +16 -4
- src/actions/class-email-translate-weglot.php +9 -43
- src/actions/class-migration-weglot.php +4 -0
- src/actions/front/class-translate-page-weglot.php +25 -328
- src/domcheckers/class-link-data-href.php +15 -0
- src/domcheckers/class-video-source.php +24 -0
- src/helpers/class-helper-filter-url-weglot.php +1 -1
- src/helpers/class-helper-json-inline-weglot.php +10 -0
- src/helpers/class-helper-replace-url-weglot.php +33 -0
- src/helpers/class-helper-tabs-admin-weglot.php +10 -0
- src/services/class-button-service-weglot.php +85 -86
- src/services/class-custom-url-service-weglot.php +79 -0
- src/services/class-email-translate-service-weglot.php +66 -0
- src/services/class-generate-switcher-service-weglot.php +128 -0
- src/services/class-href-lang-service-weglot.php +45 -0
- src/services/class-language-service-weglot.php +21 -0
- src/services/class-migration-service-weglot.php +23 -0
- src/services/class-multisite-service-weglot.php +1 -1
- src/services/class-network-service-weglot.php +0 -63
- src/services/class-option-service-weglot.php +7 -2
- src/services/class-parser-service-weglot.php +10 -2
- src/services/class-private-language-service-weglot.php +51 -0
- src/services/class-redirect-service-weglot.php +31 -5
- src/services/class-replace-link-service-weglot.php +1 -0
- src/services/class-replace-url-service-weglot.php +24 -4
- src/services/class-translate-service-weglot.php +248 -0
- templates/admin/pages/settings.php +3 -0
- templates/admin/pages/tabs/advanced.php +30 -6
- templates/admin/pages/tabs/custom-urls.php +72 -0
- templates/admin/pages/tabs/settings.php +3 -3
- vendor/autoload.php +1 -1
- vendor/composer/autoload_real.php +7 -7
- vendor/composer/autoload_static.php +4 -4
- vendor/composer/installed.json +6 -6
- vendor/weglot/weglot-php/src/Parser/Check/Dom/Placeholder.php +1 -1
- vendor/weglot/weglot-php/src/Parser/Formatter/IgnoredNodes.php +18 -4
- vendor/weglot/weglot-php/src/Parser/Parser.php +29 -2
- vendor/weglot/weglot-php/tests/unit/Client/Endpoint/CachedTranslateTest.php +8 -8
- weglot-functions.php +20 -0
- weglot.php +4 -4
app/javascripts/index.js
CHANGED
@@ -5,6 +5,7 @@ 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 |
|
@@ -15,3 +16,4 @@ InitAdminButtonPreview();
|
|
15 |
InitAdminCheckApiKey();
|
16 |
InitAdminChangeCountry();
|
17 |
InitAdminPreventSaveForm();
|
|
5 |
import InitAdminCheckApiKey from './settings/admin-check-api-key'
|
6 |
import InitAdminChangeCountry from './settings/admin-change-country'
|
7 |
import InitAdminPreventSaveForm from './settings/admin-prevent-save-form'
|
8 |
+
import InitAdminPrivateMode from './settings/admin-private-mode'
|
9 |
import './find-polyfill'
|
10 |
import './filter-polyfill'
|
11 |
|
16 |
InitAdminCheckApiKey();
|
17 |
InitAdminChangeCountry();
|
18 |
InitAdminPreventSaveForm();
|
19 |
+
InitAdminPrivateMode();
|
app/javascripts/settings/admin-private-mode.js
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const init_private_mode = function () {
|
2 |
+
|
3 |
+
const $ = jQuery
|
4 |
+
|
5 |
+
const execute = () => {
|
6 |
+
document.querySelector("#private_mode").addEventListener('change', function(e) {
|
7 |
+
|
8 |
+
document.querySelectorAll(".private-mode-lang--input").forEach((itm) => {
|
9 |
+
itm.checked = e.target.checked;
|
10 |
+
})
|
11 |
+
})
|
12 |
+
|
13 |
+
document.querySelectorAll(".private-mode-lang--input").forEach((itm) => {
|
14 |
+
itm.addEventListener('change', function(e){
|
15 |
+
if (document.querySelectorAll(".private-mode-lang--input:checked").length === 0){
|
16 |
+
document.querySelector("#private_mode").checked = false
|
17 |
+
}
|
18 |
+
})
|
19 |
+
});
|
20 |
+
}
|
21 |
+
|
22 |
+
document.addEventListener('DOMContentLoaded', () => {
|
23 |
+
if (document.querySelector('#private_mode').length != 0){
|
24 |
+
execute();
|
25 |
+
}
|
26 |
+
})
|
27 |
+
}
|
28 |
+
|
29 |
+
export default init_private_mode;
|
30 |
+
|
app/styles/admin.scss
CHANGED
@@ -335,3 +335,30 @@ input[type="text"], .wg-input-textarea {
|
|
335 |
font-size : 12px;
|
336 |
}
|
337 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
font-size : 12px;
|
336 |
}
|
337 |
}
|
338 |
+
|
339 |
+
|
340 |
+
#private_mode {
|
341 |
+
+ p + div {
|
342 |
+
display: none;
|
343 |
+
}
|
344 |
+
&:checked + p + div {
|
345 |
+
display: block;
|
346 |
+
}
|
347 |
+
}
|
348 |
+
|
349 |
+
#private-mode-detail {
|
350 |
+
margin-top: 20px;
|
351 |
+
.private-mode-detail-lang{
|
352 |
+
display:flex;
|
353 |
+
align-items:center;
|
354 |
+
margin-top: 15px;
|
355 |
+
margin-bottom: 15px;
|
356 |
+
margin-left: 15px;
|
357 |
+
input,label{
|
358 |
+
line-height: 1.3;
|
359 |
+
}
|
360 |
+
input{
|
361 |
+
margin-right: 15px;
|
362 |
+
}
|
363 |
+
}
|
364 |
+
}
|
bootstrap.php
CHANGED
@@ -39,7 +39,6 @@ abstract class Context_Weglot {
|
|
39 |
'\WeglotWP\Services\Request_Url_Service_Weglot',
|
40 |
'\WeglotWP\Services\Option_Service_Weglot',
|
41 |
'\WeglotWP\Services\Redirect_Service_Weglot',
|
42 |
-
'\WeglotWP\Services\Network_Service_Weglot',
|
43 |
'\WeglotWP\Services\Language_Service_Weglot',
|
44 |
'\WeglotWP\Services\Replace_Url_Service_Weglot',
|
45 |
'\WeglotWP\Services\Multisite_Service_Weglot',
|
@@ -53,6 +52,12 @@ abstract class Context_Weglot {
|
|
53 |
'\WeglotWP\Services\User_Api_Service_Weglot',
|
54 |
'\WeglotWP\Services\Other_Translate_Service_Weglot',
|
55 |
'\WeglotWP\Services\Dom_Checkers_Service_Weglot',
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
];
|
57 |
|
58 |
self::$context->set_services( $services );
|
@@ -94,11 +99,11 @@ function weglot_init() {
|
|
94 |
add_action( 'admin_notices', [ '\WeglotWP\Notices\Rewrite_Module_Weglot', 'admin_notice' ] );
|
95 |
}
|
96 |
|
97 |
-
if ( ! function_exists( 'curl_version' )) {
|
98 |
add_action( 'admin_notices', [ '\WeglotWP\Notices\Curl_Weglot', 'admin_notice' ] );
|
99 |
}
|
100 |
|
101 |
-
if ( ! function_exists( 'json_last_error' )) {
|
102 |
add_action( 'admin_notices', [ '\WeglotWP\Notices\Json_Function_Weglot', 'admin_notice' ] );
|
103 |
}
|
104 |
|
39 |
'\WeglotWP\Services\Request_Url_Service_Weglot',
|
40 |
'\WeglotWP\Services\Option_Service_Weglot',
|
41 |
'\WeglotWP\Services\Redirect_Service_Weglot',
|
|
|
42 |
'\WeglotWP\Services\Language_Service_Weglot',
|
43 |
'\WeglotWP\Services\Replace_Url_Service_Weglot',
|
44 |
'\WeglotWP\Services\Multisite_Service_Weglot',
|
52 |
'\WeglotWP\Services\User_Api_Service_Weglot',
|
53 |
'\WeglotWP\Services\Other_Translate_Service_Weglot',
|
54 |
'\WeglotWP\Services\Dom_Checkers_Service_Weglot',
|
55 |
+
'\WeglotWP\Services\Custom_Url_Service_Weglot',
|
56 |
+
'\WeglotWP\Services\Generate_Switcher_Service_Weglot',
|
57 |
+
'\WeglotWP\Services\Email_Translate_Service_Weglot',
|
58 |
+
'\WeglotWP\Services\Translate_Service_Weglot',
|
59 |
+
'\WeglotWP\Services\Private_Language_Service_Weglot',
|
60 |
+
'\WeglotWP\Services\Href_Lang_Service_Weglot',
|
61 |
];
|
62 |
|
63 |
self::$context->set_services( $services );
|
99 |
add_action( 'admin_notices', [ '\WeglotWP\Notices\Rewrite_Module_Weglot', 'admin_notice' ] );
|
100 |
}
|
101 |
|
102 |
+
if ( ! function_exists( 'curl_version' ) ) {
|
103 |
add_action( 'admin_notices', [ '\WeglotWP\Notices\Curl_Weglot', 'admin_notice' ] );
|
104 |
}
|
105 |
|
106 |
+
if ( ! function_exists( 'json_last_error' ) ) {
|
107 |
add_action( 'admin_notices', [ '\WeglotWP\Notices\Json_Function_Weglot', 'admin_notice' ] );
|
108 |
}
|
109 |
|
composer.json
CHANGED
@@ -17,7 +17,8 @@
|
|
17 |
},
|
18 |
"require-dev": {
|
19 |
"squizlabs/php_codesniffer": "*",
|
20 |
-
"wp-coding-standards/wpcs": "^0.13.1"
|
|
|
21 |
},
|
22 |
"scripts": {
|
23 |
"post-install-cmd": [
|
17 |
},
|
18 |
"require-dev": {
|
19 |
"squizlabs/php_codesniffer": "*",
|
20 |
+
"wp-coding-standards/wpcs": "^0.13.1",
|
21 |
+
"phpunit/phpunit": "^4"
|
22 |
},
|
23 |
"scripts": {
|
24 |
"post-install-cmd": [
|
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,{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 i="";e("#with_name").is(":checked")&&(i=c?s.local:s.code.toUpperCase()),e(".wgcurrent.wg-li").removeClass(a).addClass(l).attr("data-code-language",l).find("span").html(i)}),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(),i=e("select.flag-fr-type").val(),g=e("select.flag-ar-type").val(),f=r<=0?"":".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -"+t[r][0]+"px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -"+t[r][1]+"px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -"+t[r][2]+"px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -"+t[r][3]+"px 0 !important; } ",u=s<=0?"":".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -"+o[s][0]+"px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -"+o[s][1]+"px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -"+o[s][2]+"px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -"+o[s][3]+"px 0 !important; } ",d=c<=0?"":".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -"+l[c][0]+"px 0 !important; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -"+l[c][1]+"px 0 !important; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -"+l[c][2]+"px 0 !important; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -"+l[c][3]+"px 0 !important; } ",p=i<=0?"":".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -"+a[i][0]+"px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -"+a[i][1]+"px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -"+a[i][2]+"px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -"+a[i][3]+"px 0 !important; } ",w=g<=0?"":".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -"+n[g][0]+"px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -"+n[g][1]+"px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -"+n[g][2]+"px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -"+n[g][3]+"px 0 !important; } ";e("#flag_css, #weglot-css-flag-css").text(f+u+d+p+w)}()})};document.addEventListener("DOMContentLoaded",()=>{t()})};var i=function(){};o(0),o(1);l(),n(),a(),r(),s(),c(),i()}]);
|
1 |
+
!function(e){var t={};function o(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,o),a.l=!0,a.exports}o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)o.d(n,a,function(t){return e[t]}.bind(null,a));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/dist/",o(o.s=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 n=arguments[1],a=0;a<o;){var l=t[a];if(e.call(n,l,a,t))return l;a++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var o=this.length>>>0,n=new Array(o),a=this,l=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(a[r],r,a)&&(n[l++]=a[r]);else for(;++r!==o;)r in this&&e.call(t,a[r],r,a)&&(n[l++]=a[r]);return n.length=l,n})},,,function(e,t,o){"use strict";o.r(t);var n=function(){const e=jQuery;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 n=t[0].selectize.getValue(),a=e("#li-button-tpl");if(0===a.length)return;const l=e("#is_fullname").is(":checked"),r=e("#with_name").is(":checked");let s="";e("#with_flags").is(":checked")&&(s="weglot-flags");let c="";n.forEach(e=>{const t=weglot_languages.available.find(t=>t.code===e);let o="";r&&(o=l?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 n=e("#original_language").val();e("#original_language").on("change",function(o){const a=n,l=n;n=o.target.value,t[0].selectize.removeOption(n);const r=weglot_languages.available.find(e=>e.code===l),s=weglot_languages.available.find(e=>e.code===n);t[0].selectize.addOption(r);const c=e("#is_fullname").is(":checked");let i="";e("#with_name").is(":checked")&&(i=c?s.local:s.code.toUpperCase()),e(".wgcurrent.wg-li").removeClass(a).addClass(n).attr("data-code-language",n).find("span").html(i)}),o(),window.addEventListener("weglotCheckApi",e=>{let o=1e3;const n=e.detail.answer.plan;n<=0||weglot_languages.plans.starter_free.ids.indexOf(n)>=0?o=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(n)>=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 l=function(){jQuery;const e=()=>{const e=document.querySelector("#tpl-exclusion-url"),t=document.querySelector("#tpl-exclusion-block"),o=document.querySelector("#container-exclude_urls"),n=document.querySelector("#container-exclude_blocks");function a(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-url")&&document.querySelector("#js-add-exclude-url").addEventListener("click",t=>{t.preventDefault(),o.insertAdjacentHTML("beforeend",e.innerHTML),document.querySelector("#container-exclude_urls .item-exclude:last-child .js-btn-remove").addEventListener("click",a)}),document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",e=>{e.preventDefault(),n.insertAdjacentHTML("beforeend",t.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",a)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",a)})};document.addEventListener("DOMContentLoaded",()=>{e()})};var r=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{0!==e(".weglot-preview").length&&(()=>{let t=e("#type_flags").val(),o=[];o.push(e(".country-selector label").data("code-language")),e(".country-selector li").each((t,n)=>{o.push(e(n).data("code-language"))});const n=weglot_languages.available.filter(e=>o.indexOf(e.code)>=0);e("#weglot-css-inline").text(weglot_css.inline),e("#is_dropdown").on("change",function(){e(".country-selector").toggleClass("weglot-inline"),e(".country-selector").toggleClass("weglot-dropdown")}),e("#with_flags").on("change",function(){e(".country-selector label, .country-selector li").toggleClass("weglot-flags")}),e("#type_flags").on("change",function(o){e(".country-selector label, .country-selector li").removeClass(`flag-${t}`);const n=o.target.value;e(".country-selector label, .country-selector li").addClass(`flag-${n}`),t=n});const a=()=>{const t=n.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),a=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(a),e(".country-selector li").each((t,a)=>{const l=n.find(t=>t.code===e(a).data("code-language")),r=o?l.local:l.code.toUpperCase();e(a).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?a():(e(".country-selector label a, .country-selector label span").text(""),e(".country-selector li a, .country-selector li span").each((t,o)=>{e(o).text("")}))}),e("#is_fullname").on("change",function(t){if(e("#with_name").is(":checked"))if(t.target.checked)a();else{const t=n.find(t=>t.code===e(".country-selector label").data("code-language"));e(".country-selector label a, .country-selector label span").text(t.code.toUpperCase()),e(".country-selector li").each((t,o)=>{const a=n.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(a.code.toUpperCase()),e(o).find("span").text(a.code.toUpperCase())})}}),e("#override_css").on("keyup",function(t){e("#weglot-css-inline").text(t.target.value)})})()})};var s=function(){const e=jQuery,t=()=>{e("#api_key").blur(function(){var t=e(this).val();if(0===t.length)return e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>'),void e("#wrap-weglot #submit").prop("disabled",!0);e.getJSON("https://weglot.com/api/user-info?api_key="+t,t=>{e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-okkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!1);const o=new CustomEvent("weglotCheckApi",{detail:t});window.dispatchEvent(o)}).fail(function(){e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!0)})})};document.addEventListener("DOMContentLoaded",()=>{t()})};var c=function(){const e=jQuery;"undefined"!=typeof weglot_css&&e("#weglot-css-flag-css").text(weglot_css.flag_css);const t=()=>{e(".flag-style-openclose").on("click",function(){e(".flag-style-wrapper").toggle()}),e("select.flag-en-type, select.flag-es-type, select.flag-pt-type, select.flag-fr-type, select.flag-ar-type").on("change",function(){!function(){var t=new Array,o=new Array,n=new Array,a=new Array,l=new Array;t[1]=[3570,7841,48,2712],t[2]=[3720,449,3048,4440],t[3]=[3840,1281,2712,4224],t[4]=[3240,5217,1224,2112],t[5]=[4050,3585,1944,2496],t[6]=[2340,3457,2016,2016],o[1]=[4320,4641,3144,3552],o[2]=[3750,353,2880,4656],o[3]=[4200,1601,2568,3192],o[4]=[3990,5793,1032,2232],o[5]=[5460,897,4104,3120],o[6]=[3810,7905,216,3888],o[7]=[3630,8065,192,2376],o[8]=[3780,1473,2496,4104],o[9]=[6120,2145,4680,2568],o[10]=[4440,3009,3240,1176],o[11]=[5280,1825,3936,2976],o[12]=[4770,2081,3624,1008],o[13]=[4080,3201,2160,2544],o[14]=[4590,5761,3432,624],o[15]=[4350,2209,3360,2688],o[16]=[5610,5249,3168,528],o[17]=[5070,1729,3792,2952],o[18]=[6870,5953,96,3408],o[19]=[4020,5697,1056,1224],n[1]=[1740,5921,528,3504],a[1]=[2760,736,2856,4416],a[2]=[3840,1280,2712,4224],a[3]=[5700,7201,5016,2400],a[4]=[2220,4160,1632,1944],l[1]=[1830,129,3096,5664],l[2]=[5100,2177,3840,2904],l[3]=[4890,3425,3648,2136],l[4]=[1320,3681,1896,4080],l[5]=[1260,3841,1824,1200],l[6]=[1020,3969,1608,312],l[7]=[4800,4065,3600,72],l[8]=[4710,4865,3504,480],l[9]=[6720,5984,5112,3792],l[10]=[4500,7233,3288,1800],l[11]=[720,7522,384,3936],l[12]=[690,7745,336,1104],l[13]=[600,8225,120,1272],l[14]=[660,5569,840,576];var r=e("select.flag-en-type").val(),s=e("select.flag-es-type").val(),c=e("select.flag-pt-type").val(),i=e("select.flag-fr-type").val(),g=e("select.flag-ar-type").val(),f=r<=0?"":".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -"+t[r][0]+"px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -"+t[r][1]+"px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -"+t[r][2]+"px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -"+t[r][3]+"px 0 !important; } ",u=s<=0?"":".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -"+o[s][0]+"px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -"+o[s][1]+"px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -"+o[s][2]+"px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -"+o[s][3]+"px 0 !important; } ",d=c<=0?"":".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -"+n[c][0]+"px 0 !important; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -"+n[c][1]+"px 0 !important; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -"+n[c][2]+"px 0 !important; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -"+n[c][3]+"px 0 !important; } ",p=i<=0?"":".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -"+a[i][0]+"px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -"+a[i][1]+"px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -"+a[i][2]+"px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -"+a[i][3]+"px 0 !important; } ",w=g<=0?"":".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -"+l[g][0]+"px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -"+l[g][1]+"px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -"+l[g][2]+"px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -"+l[g][3]+"px 0 !important; } ";e("#flag_css, #weglot-css-flag-css").text(f+u+d+p+w)}()})};document.addEventListener("DOMContentLoaded",()=>{t()})};var i=function(){};var g=function(){jQuery;document.addEventListener("DOMContentLoaded",()=>{0!=document.querySelector("#private_mode").length&&(document.querySelector("#private_mode").addEventListener("change",function(e){document.querySelectorAll(".private-mode-lang--input").forEach(t=>{t.checked=e.target.checked})}),document.querySelectorAll(".private-mode-lang--input").forEach(e=>{e.addEventListener("change",function(e){0===document.querySelectorAll(".private-mode-lang--input:checked").length&&(document.querySelector("#private_mode").checked=!1)})}))})};o(0),o(1);n(),l(),a(),r(),s(),c(),i(),g()}]);
|
dist/css/admin-css.css
CHANGED
@@ -619,3 +619,28 @@ input[type="text"], .wg-input-textarea {
|
|
619 |
.flag-style-wrapper select {
|
620 |
padding: 3px !important;
|
621 |
font-size: 12px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
619 |
.flag-style-wrapper select {
|
620 |
padding: 3px !important;
|
621 |
font-size: 12px; }
|
622 |
+
|
623 |
+
#private_mode + p + div {
|
624 |
+
display: none; }
|
625 |
+
|
626 |
+
#private_mode:checked + p + div {
|
627 |
+
display: block; }
|
628 |
+
|
629 |
+
#private-mode-detail {
|
630 |
+
margin-top: 20px; }
|
631 |
+
#private-mode-detail .private-mode-detail-lang {
|
632 |
+
display: -webkit-box;
|
633 |
+
display: -webkit-flex;
|
634 |
+
display: -ms-flexbox;
|
635 |
+
display: flex;
|
636 |
+
-webkit-box-align: center;
|
637 |
+
-webkit-align-items: center;
|
638 |
+
-ms-flex-align: center;
|
639 |
+
align-items: center;
|
640 |
+
margin-top: 15px;
|
641 |
+
margin-bottom: 15px;
|
642 |
+
margin-left: 15px; }
|
643 |
+
#private-mode-detail .private-mode-detail-lang input, #private-mode-detail .private-mode-detail-lang label {
|
644 |
+
line-height: 1.3; }
|
645 |
+
#private-mode-detail .private-mode-detail-lang input {
|
646 |
+
margin-right: 15px; }
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
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: 5.0
|
6 |
Requires PHP: 5.4
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -152,6 +152,15 @@ See changelog for upgrade changes.
|
|
152 |
|
153 |
== Changelog ==
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
= 2.2.2 (05/11/2018) =
|
156 |
* Fix bug on change country flag
|
157 |
* Change load custom css inline
|
1 |
=== Translate WP website - Weglot Translate ===
|
2 |
+
Contributors: remyb92, gmulti
|
3 |
Tags: translate,translation,language,multilingual,bilingual,international,localization,multilanguage,multi language,translations,translator,multilangues,traduction,traducteur,ubersetzung,mehrsprachig,traduccion,traduzione,vertaling,vertaler,meertalig
|
4 |
Requires at least: 4.5
|
5 |
Tested up to: 5.0
|
6 |
Requires PHP: 5.4
|
7 |
+
Stable tag: 2.3.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.3.0 (05/12/2018) =
|
156 |
+
* Bugfix : Custom URL on archive page
|
157 |
+
* Bugfix : Prevent error on translate AJAX
|
158 |
+
* Bugfix : Href lang on custom URLs
|
159 |
+
* Improve code quality
|
160 |
+
* Compatibility SEOPress : exclude sitemap
|
161 |
+
* Improve private languages
|
162 |
+
* Add two DOM checkers
|
163 |
+
|
164 |
= 2.2.2 (05/11/2018) =
|
165 |
* Fix bug on change country flag
|
166 |
* Change load custom css inline
|
src/actions/admin/class-admin-enqueue-weglot.php
CHANGED
@@ -75,11 +75,14 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
|
|
75 |
$plans = $this->user_api_services->get_plans();
|
76 |
$limit = 1000;
|
77 |
if (
|
|
|
78 |
$user_info['plan'] <= 0 ||
|
|
|
79 |
in_array( $user_info['plan'], $plans['starter_free']['ids'] ) // phpcs:ignore
|
80 |
) {
|
81 |
$limit = $plans['starter_free']['limit_language'];
|
82 |
} elseif (
|
|
|
83 |
in_array( $user_info['plan'], $plans['business']['ids'] ) // phpcs:ignore
|
84 |
) {
|
85 |
$limit = $plans['business']['limit_language'];
|
75 |
$plans = $this->user_api_services->get_plans();
|
76 |
$limit = 1000;
|
77 |
if (
|
78 |
+
isset( $user_info['plan'] ) &&
|
79 |
$user_info['plan'] <= 0 ||
|
80 |
+
isset( $user_info['plan'] ) &&
|
81 |
in_array( $user_info['plan'], $plans['starter_free']['ids'] ) // phpcs:ignore
|
82 |
) {
|
83 |
$limit = $plans['starter_free']['limit_language'];
|
84 |
} elseif (
|
85 |
+
isset( $user_info['plan'] ) &&
|
86 |
in_array( $user_info['plan'], $plans['business']['ids'] ) // phpcs:ignore
|
87 |
) {
|
88 |
$limit = $plans['business']['limit_language'];
|
src/actions/admin/class-customize-menu-weglot.php
CHANGED
@@ -20,10 +20,11 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
|
|
20 |
* @since 2.0
|
21 |
*/
|
22 |
public function __construct() {
|
23 |
-
$this->language_services
|
24 |
-
$this->option_services
|
25 |
-
$this->request_url_services
|
26 |
-
$this->button_services
|
|
|
27 |
return $this;
|
28 |
}
|
29 |
|
@@ -72,20 +73,20 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
|
|
72 |
public function add_nav_menu_css_class( $classes, $item ) {
|
73 |
$str = 'weglot_menu_title-';
|
74 |
if ( strpos( $item->post_name, $str ) !== false ) {
|
75 |
-
|
|
|
|
|
76 |
$classes[] = apply_filters( 'weglot_nav_menu_link_class', 'weglot-hide' );
|
77 |
return $classes;
|
78 |
}
|
79 |
|
80 |
-
$options
|
81 |
-
$with_flags
|
82 |
-
$type_flags
|
83 |
|
84 |
-
$flag_class
|
85 |
$flag_class .= '0' === $type_flags ? '' : 'flag-' . $type_flags . ' ';
|
86 |
|
87 |
-
$lang = explode( '-', substr( $item->post_name, strlen( $str ) ) );
|
88 |
-
|
89 |
$classes[] = apply_filters( 'weglot_nav_menu_link_class', $flag_class . $lang[0] );
|
90 |
}
|
91 |
|
20 |
* @since 2.0
|
21 |
*/
|
22 |
public function __construct() {
|
23 |
+
$this->language_services = weglot_get_service( 'Language_Service_Weglot' );
|
24 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
25 |
+
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
26 |
+
$this->button_services = weglot_get_service( 'Button_Service_Weglot' );
|
27 |
+
$this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
|
28 |
return $this;
|
29 |
}
|
30 |
|
73 |
public function add_nav_menu_css_class( $classes, $item ) {
|
74 |
$str = 'weglot_menu_title-';
|
75 |
if ( strpos( $item->post_name, $str ) !== false ) {
|
76 |
+
$lang = explode( '-', substr( $item->post_name, strlen( $str ) ) );
|
77 |
+
|
78 |
+
if ( ! $this->request_url_services->is_translatable_url() || ! weglot_current_url_is_eligible() || $this->private_language_services->is_active_private_mode_for_lang( $lang[0] ) ) {
|
79 |
$classes[] = apply_filters( 'weglot_nav_menu_link_class', 'weglot-hide' );
|
80 |
return $classes;
|
81 |
}
|
82 |
|
83 |
+
$options = $this->option_services->get_options();
|
84 |
+
$with_flags = $options['with_flags'];
|
85 |
+
$type_flags = $options['type_flags'];
|
86 |
|
87 |
+
$flag_class = $with_flags ? 'weglot-flags ' : '';
|
88 |
$flag_class .= '0' === $type_flags ? '' : 'flag-' . $type_flags . ' ';
|
89 |
|
|
|
|
|
90 |
$classes[] = apply_filters( 'weglot_nav_menu_link_class', $flag_class . $lang[0] );
|
91 |
}
|
92 |
|
src/actions/admin/class-metabox-url-translate-weglot.php
CHANGED
@@ -202,6 +202,22 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
|
|
202 |
* @return void
|
203 |
*/
|
204 |
public function add_meta_boxes_url_translate() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
add_meta_box( 'weglot-url-translate', __( 'Weglot URL Translate', 'weglot' ), [ $this, 'weglot_url_translate_box' ] );
|
206 |
}
|
207 |
|
@@ -211,7 +227,12 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
|
|
211 |
* @param mixed $post
|
212 |
*/
|
213 |
public function weglot_url_translate_box( $post ) {
|
|
|
|
|
|
|
|
|
214 |
$this->custom_urls = $this->option_services->get_option( 'custom_urls' );
|
|
|
215 |
include_once WEGLOT_TEMPLATES_ADMIN_METABOXES . '/url-translate.php';
|
216 |
}
|
217 |
|
@@ -261,7 +282,6 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
|
|
261 |
return;
|
262 |
}
|
263 |
|
264 |
-
// $post = get_post( $post_id );
|
265 |
$custom_urls = $this->option_services->get_option( 'custom_urls' );
|
266 |
|
267 |
// Update new post_name
|
202 |
* @return void
|
203 |
*/
|
204 |
public function add_meta_boxes_url_translate() {
|
205 |
+
global $post;
|
206 |
+
if ( ! $post ) {
|
207 |
+
return;
|
208 |
+
}
|
209 |
+
|
210 |
+
$post_type = get_post_type();
|
211 |
+
|
212 |
+
$exclude_post_type_metabox = apply_filters( 'weglot_url_translate_metabox_post_type_exclude', [
|
213 |
+
'attachment',
|
214 |
+
'seopress_404',
|
215 |
+
] );
|
216 |
+
|
217 |
+
if ( in_array( $post_type, $exclude_post_type_metabox ) ) { //phpcs:ignore
|
218 |
+
return;
|
219 |
+
}
|
220 |
+
|
221 |
add_meta_box( 'weglot-url-translate', __( 'Weglot URL Translate', 'weglot' ), [ $this, 'weglot_url_translate_box' ] );
|
222 |
}
|
223 |
|
227 |
* @param mixed $post
|
228 |
*/
|
229 |
public function weglot_url_translate_box( $post ) {
|
230 |
+
if ( ! $post ) {
|
231 |
+
return;
|
232 |
+
}
|
233 |
+
|
234 |
$this->custom_urls = $this->option_services->get_option( 'custom_urls' );
|
235 |
+
|
236 |
include_once WEGLOT_TEMPLATES_ADMIN_METABOXES . '/url-translate.php';
|
237 |
}
|
238 |
|
282 |
return;
|
283 |
}
|
284 |
|
|
|
285 |
$custom_urls = $this->option_services->get_option( 'custom_urls' );
|
286 |
|
287 |
// Update new post_name
|
src/actions/admin/class-options-weglot.php
CHANGED
@@ -90,6 +90,11 @@ class Options_Weglot implements Hooks_Interface_Weglot {
|
|
90 |
$new_options = $this->sanitize_options_advanced( $new_options, $options );
|
91 |
}
|
92 |
break;
|
|
|
|
|
|
|
|
|
|
|
93 |
}
|
94 |
|
95 |
return $new_options;
|
@@ -157,10 +162,17 @@ class Options_Weglot implements Hooks_Interface_Weglot {
|
|
157 |
* @return array
|
158 |
*/
|
159 |
public function sanitize_options_advanced( $new_options, $options ) {
|
160 |
-
$new_options['auto_redirect']
|
161 |
-
$new_options['email_translate']
|
162 |
-
$new_options['translate_amp']
|
163 |
-
$new_options['private_mode'] = isset( $options['private_mode'] ) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
return $new_options;
|
165 |
}
|
166 |
|
90 |
$new_options = $this->sanitize_options_advanced( $new_options, $options );
|
91 |
}
|
92 |
break;
|
93 |
+
case Helper_Tabs_Admin_Weglot::CUSTOM_URLS:
|
94 |
+
if (null === $options) {
|
95 |
+
$new_options['custom_urls'] = [];
|
96 |
+
}
|
97 |
+
break;
|
98 |
}
|
99 |
|
100 |
return $new_options;
|
162 |
* @return array
|
163 |
*/
|
164 |
public function sanitize_options_advanced( $new_options, $options ) {
|
165 |
+
$new_options['auto_redirect'] = isset( $options['auto_redirect'] ) ? 1 : 0;
|
166 |
+
$new_options['email_translate'] = isset( $options['email_translate'] ) ? 1 : 0;
|
167 |
+
$new_options['translate_amp'] = isset( $options['translate_amp'] ) ? 1 : 0;
|
168 |
+
$new_options['private_mode']['active'] = isset( $options['private_mode']['active'] ) ? 1 : 0;
|
169 |
+
|
170 |
+
$languages = weglot_get_languages_configured();
|
171 |
+
|
172 |
+
foreach ( $languages as $key => $lang) {
|
173 |
+
$new_options['private_mode'][ $lang->getIso639() ] = isset( $options['private_mode'][ $lang->getIso639() ] ) ? 1 : 0;
|
174 |
+
}
|
175 |
+
|
176 |
return $new_options;
|
177 |
}
|
178 |
|
src/actions/class-email-translate-weglot.php
CHANGED
@@ -8,9 +8,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
8 |
|
9 |
use WeglotWP\Models\Hooks_Interface_Weglot;
|
10 |
|
11 |
-
use Weglot\Client\Client;
|
12 |
-
use Weglot\Parser\Parser;
|
13 |
-
use Weglot\Parser\ConfigProvider\ServerConfigProvider;
|
14 |
|
15 |
|
16 |
/**
|
@@ -25,8 +22,9 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
|
|
25 |
* @since 2.0
|
26 |
*/
|
27 |
public function __construct() {
|
28 |
-
$this->option_services
|
29 |
-
$this->request_url_services
|
|
|
30 |
}
|
31 |
|
32 |
/**
|
@@ -59,15 +57,17 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
|
|
59 |
'message' => $args['message'],
|
60 |
];
|
61 |
|
|
|
|
|
62 |
if ( $current_and_original_language['current'] !== $current_and_original_language['original'] ) {
|
63 |
-
$message_and_subject_translated = $this->translate_email( $message_and_subject, $current_and_original_language['current'] );
|
64 |
} elseif ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
|
65 |
$url = $this->request_url_services
|
66 |
->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
|
67 |
|
68 |
$choose_current_language = $url->detectCurrentLanguage();
|
69 |
if ( $choose_current_language !== $current_and_original_language['original'] ) { //If language in referer
|
70 |
-
$message_and_subject_translated = $this->translate_email( $message_and_subject, $choose_current_language );
|
71 |
} elseif ( strpos( $_SERVER['HTTP_REFERER'], 'wg_language=' ) !== false ) { //phpcs:ignore
|
72 |
//If language in parameter
|
73 |
|
@@ -75,12 +75,12 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
|
|
75 |
$start = $pos + strlen( 'wg_language=' );
|
76 |
$choose_current_language = substr( $_SERVER['HTTP_REFERER'], $start, 2 ); //phpcs:ignore
|
77 |
if ( $choose_current_language && $choose_current_language !== $current_and_original_language['original'] ) {
|
78 |
-
$message_and_subject_translated = $this->translate_email( $message_and_subject, $choose_current_language );
|
79 |
}
|
80 |
}
|
81 |
}
|
82 |
|
83 |
-
if ( strpos( $message_and_subject_translated['subject'], '</p>' ) !== false ) {
|
84 |
$pos = strpos( $message_and_subject_translated['subject'], '</p>' ) + 4;
|
85 |
$args['subject'] = substr( $message_and_subject_translated['subject'], 3, $pos - 7 );
|
86 |
$args['message'] = $message_and_subject_translated['message'];
|
@@ -88,38 +88,4 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
|
|
88 |
|
89 |
return $args;
|
90 |
}
|
91 |
-
|
92 |
-
/**
|
93 |
-
* Translate email with parser
|
94 |
-
*
|
95 |
-
* @param string $body
|
96 |
-
* @param string $language
|
97 |
-
* @param mixed $args
|
98 |
-
* @return mixed
|
99 |
-
*/
|
100 |
-
protected function translate_email( $args, $language ) {
|
101 |
-
$api_key = $this->option_services->get_option( 'api_key' );
|
102 |
-
|
103 |
-
if ( ! $api_key ) {
|
104 |
-
return $args;
|
105 |
-
}
|
106 |
-
|
107 |
-
$current_and_original_language = weglot_get_current_and_original_language();
|
108 |
-
$exclude_blocks = $this->option_services->get_exclude_blocks();
|
109 |
-
|
110 |
-
$config = new ServerConfigProvider();
|
111 |
-
$client = new Client( $api_key );
|
112 |
-
$parser = new Parser( $client, $config, $exclude_blocks );
|
113 |
-
$translated_subject = $parser->translate( '<p>' . $args['subject'] . '</p>', $current_and_original_language['original'], $current_and_original_language['current'] ); //phpcs:ignore
|
114 |
-
|
115 |
-
$config = new ServerConfigProvider();
|
116 |
-
$client = new Client( $api_key );
|
117 |
-
$parser = new Parser( $client, $config, $exclude_blocks );
|
118 |
-
$translated_message = $parser->translate( $args['message'], $current_and_original_language['original'], $current_and_original_language['current'] ); //phpcs:ignore
|
119 |
-
|
120 |
-
return [
|
121 |
-
'subject' => $translated_subject,
|
122 |
-
'message' => $translated_message,
|
123 |
-
];
|
124 |
-
}
|
125 |
}
|
8 |
|
9 |
use WeglotWP\Models\Hooks_Interface_Weglot;
|
10 |
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
/**
|
22 |
* @since 2.0
|
23 |
*/
|
24 |
public function __construct() {
|
25 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
26 |
+
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
27 |
+
$this->email_translate_services = weglot_get_service( 'Email_Translate_Service_Weglot' );
|
28 |
}
|
29 |
|
30 |
/**
|
57 |
'message' => $args['message'],
|
58 |
];
|
59 |
|
60 |
+
$message_and_subject_translated = false;
|
61 |
+
|
62 |
if ( $current_and_original_language['current'] !== $current_and_original_language['original'] ) {
|
63 |
+
$message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $current_and_original_language['current'] );
|
64 |
} elseif ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
|
65 |
$url = $this->request_url_services
|
66 |
->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
|
67 |
|
68 |
$choose_current_language = $url->detectCurrentLanguage();
|
69 |
if ( $choose_current_language !== $current_and_original_language['original'] ) { //If language in referer
|
70 |
+
$message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $choose_current_language );
|
71 |
} elseif ( strpos( $_SERVER['HTTP_REFERER'], 'wg_language=' ) !== false ) { //phpcs:ignore
|
72 |
//If language in parameter
|
73 |
|
75 |
$start = $pos + strlen( 'wg_language=' );
|
76 |
$choose_current_language = substr( $_SERVER['HTTP_REFERER'], $start, 2 ); //phpcs:ignore
|
77 |
if ( $choose_current_language && $choose_current_language !== $current_and_original_language['original'] ) {
|
78 |
+
$message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $choose_current_language );
|
79 |
}
|
80 |
}
|
81 |
}
|
82 |
|
83 |
+
if ( $message_and_subject_translated && strpos( $message_and_subject_translated['subject'], '</p>' ) !== false ) {
|
84 |
$pos = strpos( $message_and_subject_translated['subject'], '</p>' ) + 4;
|
85 |
$args['subject'] = substr( $message_and_subject_translated['subject'], 3, $pos - 7 );
|
86 |
$args['message'] = $message_and_subject_translated['message'];
|
88 |
|
89 |
return $args;
|
90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
}
|
src/actions/class-migration-weglot.php
CHANGED
@@ -35,5 +35,9 @@ class Migration_Weglot implements Hooks_Interface_Weglot {
|
|
35 |
if ( ! $weglot_version && version_compare( WEGLOT_LATEST_VERSION, '2.0', '<' ) ) {
|
36 |
$this->migration_services->update_v200();
|
37 |
}
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
}
|
35 |
if ( ! $weglot_version && version_compare( WEGLOT_LATEST_VERSION, '2.0', '<' ) ) {
|
36 |
$this->migration_services->update_v200();
|
37 |
}
|
38 |
+
|
39 |
+
if ( $weglot_version && version_compare( $weglot_version, '2.2.0', '>=' ) && version_compare( $weglot_version, '2.3.0', '<' ) ) {
|
40 |
+
$this->migration_services->update_v230();
|
41 |
+
}
|
42 |
}
|
43 |
}
|
src/actions/front/class-translate-page-weglot.php
CHANGED
@@ -26,16 +26,12 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
|
|
26 |
* @since 2.0
|
27 |
*/
|
28 |
public function __construct() {
|
29 |
-
$this->option_services
|
30 |
-
$this->
|
31 |
-
$this->
|
32 |
-
$this->
|
33 |
-
$this->
|
34 |
-
$this->
|
35 |
-
$this->language_services = weglot_get_service( 'Language_Service_Weglot' );
|
36 |
-
$this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
|
37 |
-
$this->wc_active_services = weglot_get_service( 'WC_Active_Weglot' );
|
38 |
-
$this->other_translate_services = weglot_get_service( 'Other_Translate_Service_Weglot' );
|
39 |
}
|
40 |
|
41 |
/**
|
@@ -64,9 +60,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
|
|
64 |
|
65 |
$this->current_language = $this->request_url_services->get_current_language();
|
66 |
|
67 |
-
|
68 |
-
$private_mode = $this->option_services->get_option( 'private_mode' );
|
69 |
-
if ( $private_mode && ! current_user_can( $role_private_mode ) ) {
|
70 |
return;
|
71 |
}
|
72 |
|
@@ -89,19 +83,25 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
|
|
89 |
'avia_ajax_switch_menu_walker', // Enfold theme
|
90 |
'query-themes', // WP Core
|
91 |
'wpestate_ajax_check_booking_valability_internal', // WP Estate theme
|
|
|
92 |
] );
|
93 |
|
94 |
if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && in_array( $_POST['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
|
95 |
return true;
|
96 |
}
|
97 |
|
|
|
|
|
|
|
|
|
98 |
return false;
|
99 |
}
|
100 |
|
|
|
101 |
/**
|
102 |
* @see init
|
103 |
* @since 2.0
|
104 |
-
* @version 2.0
|
105 |
* @return void
|
106 |
*/
|
107 |
public function weglot_init() {
|
@@ -145,79 +145,20 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
|
|
145 |
return;
|
146 |
}
|
147 |
|
148 |
-
|
149 |
-
}
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
/**
|
154 |
-
* @since 2.0
|
155 |
-
* @version 2.0.4
|
156 |
-
*
|
157 |
-
* @param array $array
|
158 |
-
* @return array
|
159 |
-
*/
|
160 |
-
public function translate_array( $array ) {
|
161 |
-
$array_not_ajax_html = apply_filters( 'weglot_array_not_ajax_html', [ 'redirecturl', 'url' ] );
|
162 |
-
|
163 |
-
foreach ( $array as $key => $val ) {
|
164 |
-
if ( is_array( $val ) ) {
|
165 |
-
$array[ $key ] = $this->translate_array( $val );
|
166 |
-
} else {
|
167 |
-
if ( $this->is_ajax_html( $val ) ) {
|
168 |
-
$parser = $this->parser_services->get_parser();
|
169 |
-
$array[$key] = $parser->translate( $val, $this->original_language, $this->current_language ); //phpcs:ignore
|
170 |
-
} elseif ( in_array( $key, $array_not_ajax_html ) ) { //phpcs:ignore
|
171 |
-
$array[$key] = $this->replace_link_services->replace_url( $val ); //phpcs:ignore
|
172 |
-
}
|
173 |
-
}
|
174 |
-
}
|
175 |
-
|
176 |
-
return $array;
|
177 |
-
}
|
178 |
-
|
179 |
-
/**
|
180 |
-
* Replace links for JSON translate
|
181 |
-
*
|
182 |
-
* @since 2.1.0
|
183 |
-
*
|
184 |
-
* @param array $array
|
185 |
-
* @return array
|
186 |
-
*/
|
187 |
-
public function replace_link_array( $array ) {
|
188 |
-
$array_not_ajax_html = apply_filters( 'weglot_array_not_ajax_html', [ 'redirecturl', 'url' ] );
|
189 |
-
|
190 |
-
foreach ( $array as $key => $val ) {
|
191 |
-
if ( is_array( $val ) ) {
|
192 |
-
$array[ $key ] = $this->replace_link_array( $val );
|
193 |
-
} else {
|
194 |
-
if ( $this->is_ajax_html( $val ) ) {
|
195 |
-
$array[ $key ] = $this->weglot_replace_link( $val );
|
196 |
-
}
|
197 |
-
}
|
198 |
-
}
|
199 |
-
|
200 |
-
return $array;
|
201 |
-
}
|
202 |
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
*/
|
209 |
-
public function is_ajax_html( $string ) {
|
210 |
-
$preg_match_ajax_html = apply_filters( 'weglot_is_ajax_html_regex', '/<(a|div|span|p|i|aside|input|textarea|select|h1|h2|h3|h4|meta|button|form|li|strong|ul|option)/' );
|
211 |
-
$result = preg_match_all( $preg_match_ajax_html, $string, $m, PREG_PATTERN_ORDER );
|
212 |
-
|
213 |
-
if ( isset( $string[0] ) && '{' !== $string[0] && $result && $result >= 1 ) {
|
214 |
-
return true;
|
215 |
} else {
|
216 |
-
|
217 |
}
|
218 |
}
|
219 |
|
220 |
|
|
|
221 |
/**
|
222 |
* @since 2.0
|
223 |
*
|
@@ -245,7 +186,6 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
|
|
245 |
'/',
|
246 |
$_SERVER['REQUEST_URI'] //phpcs:ignore
|
247 |
);
|
248 |
-
return;
|
249 |
}
|
250 |
|
251 |
/**
|
@@ -286,7 +226,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
|
|
286 |
return;
|
287 |
}
|
288 |
|
289 |
-
$key_slug = array_search( $slug_in_work, $custom_urls[ $current_language ] );
|
290 |
|
291 |
// No custom URL for this language with this slug
|
292 |
if ( ! isset( $custom_urls[ $current_language ][ $slug_in_work ] ) && false === $key_slug ) {
|
@@ -319,257 +259,14 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
|
|
319 |
}
|
320 |
}
|
321 |
|
322 |
-
/**
|
323 |
-
* @since 2.0.2
|
324 |
-
*
|
325 |
-
* Check if there are Weglot menu links and make sure there is the data-wg-notranslate
|
326 |
-
* @param string $content
|
327 |
-
* @return string
|
328 |
-
*/
|
329 |
-
public function fix_menu_link( $content ) {
|
330 |
-
$content = preg_replace( '#<a([^\>]+?)?href="(http|https):\/\/\[weglot_#', '<a$1 data-wg-notranslate="true" href="$2://[weglot_', $content );
|
331 |
-
|
332 |
-
return $content;
|
333 |
-
}
|
334 |
-
|
335 |
-
/**
|
336 |
-
* @see weglot_init / ob_start
|
337 |
-
* @since 2.0
|
338 |
-
* @version 2.0.4
|
339 |
-
* @param string $content
|
340 |
-
* @return string
|
341 |
-
*/
|
342 |
-
public function weglot_treat_page( $content ) {
|
343 |
-
$this->current_language = $this->request_url_services->get_current_language(); // Need to reset
|
344 |
-
$allowed = $this->option_services->get_option( 'allowed' );
|
345 |
-
// Choose type translate
|
346 |
-
$type = ( $this->is_json( $content ) ) ? 'json' : 'html';
|
347 |
-
$type = apply_filters( 'weglot_type_treat_page', $type );
|
348 |
-
|
349 |
-
if ( ! $allowed ) {
|
350 |
-
$content = $this->weglot_render_dom( $content );
|
351 |
-
if ( 'json' === $type || wp_doing_ajax() ) {
|
352 |
-
return $content;
|
353 |
-
}
|
354 |
-
|
355 |
-
return $content . '<!--Not allowed-->';
|
356 |
-
}
|
357 |
-
|
358 |
-
$active_translation = apply_filters( 'weglot_active_translation', true );
|
359 |
-
|
360 |
-
// No need to translate but prepare new dom with button
|
361 |
-
if ( $this->current_language === $this->original_language || ! $active_translation ) {
|
362 |
-
return $this->weglot_render_dom( $content );
|
363 |
-
}
|
364 |
-
|
365 |
-
$parser = $this->parser_services->get_parser();
|
366 |
-
|
367 |
-
try {
|
368 |
-
switch ( $type ) {
|
369 |
-
case 'json':
|
370 |
-
$json = \json_decode( $content, true );
|
371 |
-
$content = $this->translate_array( $json );
|
372 |
-
$content = $this->replace_link_array( $content );
|
373 |
-
$content = apply_filters( 'weglot_json_treat_page', $content );
|
374 |
-
|
375 |
-
return wp_json_encode( $content );
|
376 |
-
break;
|
377 |
-
case 'html':
|
378 |
-
$content = $this->fix_menu_link( $content );
|
379 |
-
$translated_content = $parser->translate( $content, $this->original_language, $this->current_language ); // phpcs:ignore
|
380 |
-
|
381 |
-
if ( $this->wc_active_services->is_active() ) {
|
382 |
-
// @TODO : Improve this with multiple service
|
383 |
-
$translated_content = weglot_get_service( 'WC_Translate_Weglot' )->translate_words( $translated_content );
|
384 |
-
}
|
385 |
-
|
386 |
-
$translated_content = $this->other_translate_services->translate_words( $translated_content );
|
387 |
-
|
388 |
-
$translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
|
389 |
-
|
390 |
-
return $this->weglot_render_dom( $translated_content );
|
391 |
-
break;
|
392 |
-
default:
|
393 |
-
$name_filter = sprintf( 'weglot_%s_treat_page', $type );
|
394 |
-
return apply_filters( $name_filter, $content, $parser, $this->original_language, $this->current_language );
|
395 |
-
break;
|
396 |
-
|
397 |
-
}
|
398 |
-
} catch ( ApiError $e ) {
|
399 |
-
if ( 'json' !== $type ) {
|
400 |
-
$content .= '<!--Weglot error API : ' . $this->remove_comments( $e->getMessage() ) . '-->';
|
401 |
-
}
|
402 |
-
if ( strpos( $e->getMessage(), 'NMC' ) !== false ) {
|
403 |
-
$this->option_services->set_option_by_key( 'allowed', false );
|
404 |
-
}
|
405 |
-
return $content;
|
406 |
-
} catch ( \Exception $e ) {
|
407 |
-
if ( 'json' !== $type ) {
|
408 |
-
$content .= '<!--Weglot error : ' . $this->remove_comments( $e->getMessage() ) . '-->';
|
409 |
-
}
|
410 |
-
return $content;
|
411 |
-
}
|
412 |
-
}
|
413 |
-
|
414 |
-
/**
|
415 |
-
* @since 2.0
|
416 |
-
*
|
417 |
-
* @param string $html
|
418 |
-
* @return string
|
419 |
-
*/
|
420 |
-
private function remove_comments( $html ) {
|
421 |
-
return preg_replace( '/<!--(.*)-->/Uis', '', $html );
|
422 |
-
}
|
423 |
-
|
424 |
-
/**
|
425 |
-
* @since 2.0
|
426 |
-
*
|
427 |
-
* @param string $string
|
428 |
-
* @return boolean
|
429 |
-
*/
|
430 |
-
public function is_json( $string ) {
|
431 |
-
return is_string( $string ) && is_array( \json_decode( $string, true ) ) && ( JSON_ERROR_NONE === \json_last_error() ) ? true : false;
|
432 |
-
}
|
433 |
-
|
434 |
-
/**
|
435 |
-
* @since 2.0
|
436 |
-
* @param string $dom
|
437 |
-
* @return string
|
438 |
-
*/
|
439 |
-
public function weglot_add_button_html( $dom ) {
|
440 |
-
$options = $this->option_services->get_options();
|
441 |
-
|
442 |
-
// Place the button if we see markup
|
443 |
-
if ( strpos( $dom, '<div id="weglot_here"></div>' ) !== false ) {
|
444 |
-
$button_html = $this->button_services->get_html( 'weglot-shortcode' );
|
445 |
-
$dom = str_replace( '<div id="weglot_here"></div>', $button_html, $dom );
|
446 |
-
}
|
447 |
-
|
448 |
-
if ( strpos( $dom, '[weglot_menu' ) !== false ) {
|
449 |
-
$languages_configured = $this->language_services->get_languages_configured();
|
450 |
-
|
451 |
-
$is_fullname = $options['is_fullname'];
|
452 |
-
$with_name = $options['with_name'];
|
453 |
-
|
454 |
-
$url = $this->request_url_services->get_weglot_url();
|
455 |
-
// Custom URLS
|
456 |
-
$request_without_language = array_filter( explode( '/', $url->getPath() ), 'strlen' );
|
457 |
-
$index_entries = count( $request_without_language );
|
458 |
-
$custom_urls = $this->option_services->get_option( 'custom_urls' );
|
459 |
-
global $post;
|
460 |
-
|
461 |
-
foreach ( $languages_configured as $language ) {
|
462 |
-
$shortcode_title = sprintf( '\[weglot_menu_title-%s\]', $language->getIso639() );
|
463 |
-
$shortcode_title_without_bracket = sprintf( 'weglot_menu_title-%s', $language->getIso639() );
|
464 |
-
$shortcode_title_html = str_replace( '\[', '%5B', $shortcode_title );
|
465 |
-
$shortcode_title_html = str_replace( '\]', '%5D', $shortcode_title_html );
|
466 |
-
$shortcode_url = sprintf( '(http|https):\/\/\[weglot_menu_current_url-%s\]', $language->getIso639() );
|
467 |
-
$shortcode_url_html = str_replace( '\[', '%5B', $shortcode_url );
|
468 |
-
$shortcode_url_html = str_replace( '\]', '%5D', $shortcode_url_html );
|
469 |
-
|
470 |
-
$name = '';
|
471 |
-
if ( $with_name ) {
|
472 |
-
$name = ( $is_fullname ) ? $language->getLocalName() : strtoupper( $language->getIso639() );
|
473 |
-
}
|
474 |
-
|
475 |
-
$dom = preg_replace( '#' . $shortcode_title . '#i', $name, $dom );
|
476 |
-
$dom = preg_replace( '#' . $shortcode_title_html . '#i', $name, $dom );
|
477 |
-
$dom = preg_replace( '#' . $shortcode_title_without_bracket . '#i', $name, $dom );
|
478 |
-
|
479 |
-
$link_menu = $url->getForLanguage( $language->getIso639() );
|
480 |
-
if ( weglot_has_auto_redirect() && strpos( $link_menu, 'no_lredirect' ) === false && ( is_home() || is_front_page() ) && $language->getIso639() === weglot_get_original_language() ) {
|
481 |
-
$link_menu .= '?no_lredirect=true';
|
482 |
-
}
|
483 |
-
|
484 |
-
if ( isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) ) {
|
485 |
-
$slug_in_work = $request_without_language[ $index_entries ];
|
486 |
-
$key_code = $language->getIso639();
|
487 |
-
|
488 |
-
// Search from original slug
|
489 |
-
$key_slug = false;
|
490 |
-
if ( isset( $custom_urls[ $key_code ] ) && $post ) {
|
491 |
-
$key_slug = array_search( $post->post_name, $custom_urls[ $key_code ] );
|
492 |
-
}
|
493 |
-
|
494 |
-
if ( false !== $key_slug ) {
|
495 |
-
$link_menu = str_replace( $slug_in_work, $key_slug, $link_menu );
|
496 |
-
} else {
|
497 |
-
$link_menu = str_replace( $slug_in_work, $post->post_name, $link_menu );
|
498 |
-
}
|
499 |
-
}
|
500 |
-
|
501 |
-
// Compatibility Menu HTTPS if not work. Since 2.0.6
|
502 |
-
if (
|
503 |
-
(
|
504 |
-
is_ssl() ||
|
505 |
-
isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] // phpcs:ignore
|
506 |
-
) &&
|
507 |
-
strpos( $link_menu, 'https://' ) === false
|
508 |
-
) {
|
509 |
-
$link_menu = str_replace( 'http', 'https', $link_menu );
|
510 |
-
}
|
511 |
-
|
512 |
-
$dom = preg_replace( '#' . $shortcode_url . '#i', $link_menu, $dom );
|
513 |
-
$dom = preg_replace( '#' . $shortcode_url_html . '#i', $link_menu, $dom );
|
514 |
-
}
|
515 |
-
|
516 |
-
$dom .= sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
|
517 |
-
}
|
518 |
-
|
519 |
-
// Place the button if not in the page
|
520 |
-
if ( strpos( $dom, sprintf( '<!--Weglot %s-->', WEGLOT_VERSION ) ) === false ) {
|
521 |
-
$button_html = $this->button_services->get_html( 'weglot-default' );
|
522 |
-
$dom = ( strpos( $dom, '</body>' ) !== false) ? str_replace( '</body>', $button_html . ' </body>', $dom ) : str_replace( '</footer>', $button_html . ' </footer>', $dom );
|
523 |
-
}
|
524 |
-
|
525 |
-
return $dom;
|
526 |
-
}
|
527 |
-
|
528 |
-
/**
|
529 |
-
* @since 2.0
|
530 |
-
* @param string $dom
|
531 |
-
* @return string
|
532 |
-
*/
|
533 |
-
public function weglot_replace_link( $dom ) {
|
534 |
-
$dom = $this->replace_url_services->modify_link( '/<a([^\>]+?)?href=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/', $dom, 'a' );
|
535 |
-
$dom = $this->replace_url_services->modify_link( '/<([^\>]+?)?data-link=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/', $dom, 'datalink' );
|
536 |
-
$dom = $this->replace_url_services->modify_link( '/<([^\>]+?)?data-url=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/', $dom, 'dataurl' );
|
537 |
-
$dom = $this->replace_url_services->modify_link( '/<([^\>]+?)?data-cart-url=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/', $dom, 'datacart' );
|
538 |
-
$dom = $this->replace_url_services->modify_link( '/<form([^\>]+?)?action=(\"|\')([^\s\>]+?)(\"|\')/', $dom, 'form' );
|
539 |
-
$dom = $this->replace_url_services->modify_link( '/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/', $dom, 'canonical' );
|
540 |
-
$dom = $this->replace_url_services->modify_link( '/<link rel="amphtml"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/', $dom, 'amp' );
|
541 |
-
$dom = $this->replace_url_services->modify_link( '/<meta property="og:url"(.*?)?content=(\"|\')([^\s\>]+?)(\"|\')/', $dom, 'meta' );
|
542 |
-
|
543 |
-
return apply_filters( 'weglot_replace_link', $dom );
|
544 |
-
}
|
545 |
-
|
546 |
-
/**
|
547 |
-
* @since 2.0
|
548 |
-
* @version 2.0.4
|
549 |
-
* @param string $dom
|
550 |
-
* @return string
|
551 |
-
*/
|
552 |
-
public function weglot_render_dom( $dom ) {
|
553 |
-
$dom = $this->weglot_add_button_html( $dom );
|
554 |
-
|
555 |
-
// We only need this on translated page
|
556 |
-
if ( $this->current_language !== $this->original_language ) {
|
557 |
-
$dom = $this->weglot_replace_link( $dom );
|
558 |
-
|
559 |
-
$dom = preg_replace( '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/', '<html $1lang=$2' . $this->current_language . '$4', $dom );
|
560 |
-
$dom = preg_replace( '/property="og:locale" content=(\"|\')(\S*)(\"|\')/', 'property="og:locale" content=$1' . $this->current_language . '$3', $dom );
|
561 |
-
}
|
562 |
-
return apply_filters( 'weglot_render_dom', $dom );
|
563 |
-
}
|
564 |
-
|
565 |
/**
|
566 |
* @see wp_head
|
567 |
* @since 2.0
|
|
|
568 |
* @return void
|
569 |
*/
|
570 |
public function weglot_href_lang() {
|
571 |
-
|
572 |
-
echo apply_filters( 'weglot_href_lang', $href_lang_tags ); //phpcs:ignore
|
573 |
}
|
574 |
}
|
575 |
|
26 |
* @since 2.0
|
27 |
*/
|
28 |
public function __construct() {
|
29 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
30 |
+
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
31 |
+
$this->redirect_services = weglot_get_service( 'Redirect_Service_Weglot' );
|
32 |
+
$this->translate_services = weglot_get_service( 'Translate_Service_Weglot' );
|
33 |
+
$this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
|
34 |
+
$this->href_lang_services = weglot_get_service( 'Href_Lang_Service_Weglot' );
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
|
37 |
/**
|
60 |
|
61 |
$this->current_language = $this->request_url_services->get_current_language();
|
62 |
|
63 |
+
if ( $this->private_language_services->is_active_private_mode_for_lang( $this->current_language ) ) {
|
|
|
|
|
64 |
return;
|
65 |
}
|
66 |
|
83 |
'avia_ajax_switch_menu_walker', // Enfold theme
|
84 |
'query-themes', // WP Core
|
85 |
'wpestate_ajax_check_booking_valability_internal', // WP Estate theme
|
86 |
+
'mailster_get_template', // Mailster Pro
|
87 |
] );
|
88 |
|
89 |
if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && in_array( $_POST['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
|
90 |
return true;
|
91 |
}
|
92 |
|
93 |
+
if ( 'GET' === $_SERVER['REQUEST_METHOD'] && isset( $_GET['action'] ) && in_array( $_GET['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
|
94 |
+
return true;
|
95 |
+
}
|
96 |
+
|
97 |
return false;
|
98 |
}
|
99 |
|
100 |
+
|
101 |
/**
|
102 |
* @see init
|
103 |
* @since 2.0
|
104 |
+
* @version 2.3.0
|
105 |
* @return void
|
106 |
*/
|
107 |
public function weglot_init() {
|
145 |
return;
|
146 |
}
|
147 |
|
148 |
+
$file = apply_filters( 'weglot_debug_file', WEGLOT_DIR . '/content.html' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
+
if ( defined( 'WEGLOT_DEBUG' ) && WEGLOT_DEBUG && file_exists( $file ) ) {
|
151 |
+
$this->translate_services->set_original_language( weglot_get_original_language() );
|
152 |
+
$this->translate_services->set_current_language( $this->request_url_services->get_current_language() );
|
153 |
+
echo $this->translate_services->weglot_treat_page( file_get_contents( $file ) ); //phpcs:ignore
|
154 |
+
die;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
} else {
|
156 |
+
$this->translate_services->weglot_translate();
|
157 |
}
|
158 |
}
|
159 |
|
160 |
|
161 |
+
|
162 |
/**
|
163 |
* @since 2.0
|
164 |
*
|
186 |
'/',
|
187 |
$_SERVER['REQUEST_URI'] //phpcs:ignore
|
188 |
);
|
|
|
189 |
}
|
190 |
|
191 |
/**
|
226 |
return;
|
227 |
}
|
228 |
|
229 |
+
$key_slug = array_search( $slug_in_work, $custom_urls[ $current_language ] ); //phpcs:ignore
|
230 |
|
231 |
// No custom URL for this language with this slug
|
232 |
if ( ! isset( $custom_urls[ $current_language ][ $slug_in_work ] ) && false === $key_slug ) {
|
259 |
}
|
260 |
}
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
/**
|
263 |
* @see wp_head
|
264 |
* @since 2.0
|
265 |
+
* @version 2.3.0
|
266 |
* @return void
|
267 |
*/
|
268 |
public function weglot_href_lang() {
|
269 |
+
echo $this->href_lang_services->generate_href_lang_tags(); //phpcs:ignore
|
|
|
270 |
}
|
271 |
}
|
272 |
|
src/domcheckers/class-link-data-href.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace WeglotWP\Domcheckers;
|
3 |
+
|
4 |
+
use Weglot\Parser\Check\Dom\LinkHref;
|
5 |
+
|
6 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
7 |
+
exit;
|
8 |
+
}
|
9 |
+
|
10 |
+
class Link_Data_Href extends LinkHref {
|
11 |
+
/**
|
12 |
+
* {@inheritdoc}
|
13 |
+
*/
|
14 |
+
const PROPERTY = 'data-href';
|
15 |
+
}
|
src/domcheckers/class-video-source.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WeglotWP\Domcheckers;
|
4 |
+
|
5 |
+
use Weglot\Parser\Check\Dom\AbstractDomChecker;
|
6 |
+
use Weglot\Client\Api\Enum\WordType;
|
7 |
+
|
8 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
9 |
+
exit;
|
10 |
+
}
|
11 |
+
class Video_Source extends AbstractDomChecker {
|
12 |
+
/**
|
13 |
+
* {@inheritdoc}
|
14 |
+
*/
|
15 |
+
const DOM = 'video source';
|
16 |
+
/**
|
17 |
+
* {@inheritdoc}
|
18 |
+
*/
|
19 |
+
const PROPERTY = 'src';
|
20 |
+
/**
|
21 |
+
* {@inheritdoc}
|
22 |
+
*/
|
23 |
+
const WORD_TYPE = WordType::IMG_SRC;
|
24 |
+
}
|
src/helpers/class-helper-filter-url-weglot.php
CHANGED
@@ -19,7 +19,7 @@ abstract class Helper_Filter_Url_Weglot {
|
|
19 |
* @return string
|
20 |
*/
|
21 |
protected static function get_clean_base_url( $url ) {
|
22 |
-
if ( strpos( $url,
|
23 |
$url = sprintf( '%s%s', get_site_url(), $url );
|
24 |
}
|
25 |
|
19 |
* @return string
|
20 |
*/
|
21 |
protected static function get_clean_base_url( $url ) {
|
22 |
+
if ( strpos( $url, 'http' ) === false ) {
|
23 |
$url = sprintf( '%s%s', get_site_url(), $url );
|
24 |
}
|
25 |
|
src/helpers/class-helper-json-inline-weglot.php
CHANGED
@@ -31,4 +31,14 @@ abstract class Helper_Json_Inline_Weglot {
|
|
31 |
$string = str_replace( '"', '', str_replace( '/', '\\\\/', str_replace( '\\u', '\\\\u', \json_encode( $string ) ) ) ); //phpcs:ignore
|
32 |
return $string;
|
33 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
31 |
$string = str_replace( '"', '', str_replace( '/', '\\\\/', str_replace( '\\u', '\\\\u', \json_encode( $string ) ) ) ); //phpcs:ignore
|
32 |
return $string;
|
33 |
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* @since 2.3.0
|
37 |
+
*
|
38 |
+
* @param string $string
|
39 |
+
* @return boolean
|
40 |
+
*/
|
41 |
+
public static function is_json( $string ) {
|
42 |
+
return is_string( $string ) && is_array( \json_decode( $string, true ) ) && ( JSON_ERROR_NONE === \json_last_error() ) ? true : false;
|
43 |
+
}
|
44 |
}
|
src/helpers/class-helper-replace-url-weglot.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.3.0
|
12 |
+
*/
|
13 |
+
class Helper_Replace_Url_Weglot {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @since 2.3.0
|
17 |
+
* @return array
|
18 |
+
*/
|
19 |
+
public static function get_replace_modify_link() {
|
20 |
+
$data = [
|
21 |
+
'a' => '/<a([^\>]+?)?href=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
|
22 |
+
'datalink' => '/<([^\>]+?)?data-link=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
|
23 |
+
'dataurl' => '/<([^\>]+?)?data-url=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
|
24 |
+
'datacart' => '/<([^\>]+?)?data-cart-url=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
|
25 |
+
'form' => '/<form([^\>]+?)?action=(\"|\')([^\s\>]+?)(\"|\')/',
|
26 |
+
'canonical' => '/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/',
|
27 |
+
'amp' => '/<link rel="amphtml"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/',
|
28 |
+
'meta' => '/<meta property="og:url"(.*?)?content=(\"|\')([^\s\>]+?)(\"|\')/',
|
29 |
+
];
|
30 |
+
|
31 |
+
return apply_filters( 'weglot_get_replace_modify_link', $data );
|
32 |
+
}
|
33 |
+
}
|
src/helpers/class-helper-tabs-admin-weglot.php
CHANGED
@@ -23,6 +23,11 @@ abstract class Helper_Tabs_Admin_Weglot {
|
|
23 |
*/
|
24 |
const STATUS = 'status';
|
25 |
|
|
|
|
|
|
|
|
|
|
|
26 |
/**
|
27 |
* Get tabs constant
|
28 |
*
|
@@ -34,6 +39,7 @@ abstract class Helper_Tabs_Admin_Weglot {
|
|
34 |
return [
|
35 |
self::SETTINGS,
|
36 |
self::STATUS,
|
|
|
37 |
];
|
38 |
}
|
39 |
|
@@ -54,6 +60,10 @@ abstract class Helper_Tabs_Admin_Weglot {
|
|
54 |
'title' => __( 'Status', 'weglot' ),
|
55 |
'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::STATUS ) ),
|
56 |
],
|
|
|
|
|
|
|
|
|
57 |
];
|
58 |
}
|
59 |
}
|
23 |
*/
|
24 |
const STATUS = 'status';
|
25 |
|
26 |
+
/**
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
const CUSTOM_URLS = 'custom-urls';
|
30 |
+
|
31 |
/**
|
32 |
* Get tabs constant
|
33 |
*
|
39 |
return [
|
40 |
self::SETTINGS,
|
41 |
self::STATUS,
|
42 |
+
self::CUSTOM_URLS
|
43 |
];
|
44 |
}
|
45 |
|
60 |
'title' => __( 'Status', 'weglot' ),
|
61 |
'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::STATUS ) ),
|
62 |
],
|
63 |
+
self::CUSTOM_URLS => [
|
64 |
+
'title' => __( 'Custom URLs', 'weglot' ),
|
65 |
+
'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::CUSTOM_URLS ) ),
|
66 |
+
],
|
67 |
];
|
68 |
}
|
69 |
}
|
src/services/class-button-service-weglot.php
CHANGED
@@ -6,8 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
6 |
exit;
|
7 |
}
|
8 |
|
9 |
-
use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
|
10 |
-
|
11 |
/**
|
12 |
* Button services
|
13 |
*
|
@@ -19,66 +17,108 @@ class Button_Service_Weglot {
|
|
19 |
* @since 2.0
|
20 |
*/
|
21 |
public function __construct() {
|
22 |
-
$this->option_services
|
23 |
-
$this->request_url_services
|
24 |
-
$this->language_services
|
25 |
-
$this->amp_services
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
|
28 |
|
|
|
29 |
/**
|
30 |
* Get html button switcher
|
31 |
*
|
32 |
* @since 2.0
|
|
|
33 |
* @return string
|
34 |
* @param string $add_class
|
35 |
*/
|
36 |
public function get_html( $add_class = '' ) {
|
37 |
-
$
|
38 |
-
$
|
39 |
-
|
40 |
-
$
|
41 |
-
$
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
50 |
}
|
51 |
|
52 |
-
$
|
53 |
-
$
|
54 |
-
$
|
55 |
|
56 |
-
$
|
57 |
-
$flag_class .= '0' === $type_flags ? '' : 'flag-' . $type_flags . ' ';
|
58 |
|
59 |
-
|
|
|
|
|
60 |
|
61 |
-
$
|
|
|
62 |
|
63 |
$button_html = sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
|
64 |
$button_html .= sprintf( "<aside data-wg-notranslate class='country-selector %s'>", $class_aside . $add_class );
|
65 |
|
66 |
if ( ! empty( $original_language ) && ! empty( $destination_language ) ) {
|
67 |
-
$
|
68 |
-
|
69 |
-
$current_language_entry = $languages[ $current_language ];
|
70 |
-
} else {
|
71 |
-
$current_language_entry = apply_filters( 'weglot_current_language_entry', $current_language );
|
72 |
-
if ( $current_language_entry === $current_language ) {
|
73 |
-
throw new \Exception( 'You need create a language entry' );
|
74 |
-
}
|
75 |
-
}
|
76 |
-
|
77 |
-
if ( $with_name ) {
|
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 );
|
@@ -88,57 +128,16 @@ class Button_Service_Weglot {
|
|
88 |
array_unshift( $destination_language, $original_language );
|
89 |
|
90 |
foreach ( $destination_language as $key => $key_code ) {
|
91 |
-
if ( $key_code === $current_language ) {
|
92 |
continue;
|
93 |
}
|
94 |
|
95 |
-
if ( isset( $languages[ $key_code ] ) ) {
|
96 |
-
$current_language_entry = $languages[ $key_code ];
|
97 |
-
} else {
|
98 |
-
$current_language_entry = apply_filters( 'weglot_current_language_entry', $key_code );
|
99 |
-
if ( $current_language_entry === $key_code ) {
|
100 |
-
throw new \Exception( 'You need create a language entry' );
|
101 |
-
}
|
102 |
-
}
|
103 |
-
|
104 |
-
$name = '';
|
105 |
-
if ( $with_name ) {
|
106 |
-
$name = ( $is_fullname ) ? $current_language_entry->getLocalName() : strtoupper( $current_language_entry->getIso639() );
|
107 |
-
}
|
108 |
-
|
109 |
$button_html .= sprintf( '<li class="wg-li %s" data-code-language="%s">', $flag_class . $key_code, $key_code );
|
110 |
|
111 |
-
$
|
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 |
-
if ( $post ) {
|
131 |
-
$url_lang = str_replace( $slug_in_work, $post->post_name, $url_lang );
|
132 |
-
}
|
133 |
-
}
|
134 |
-
}
|
135 |
|
136 |
-
$link_button =
|
137 |
-
|
138 |
-
$link_button = preg_replace( '#\?no_lredirect=true$#', '', $link_button ); // Remove ending "?no_lredirect=true"
|
139 |
-
if ( weglot_has_auto_redirect() && strpos( $link_button, 'no_lredirect' ) === false && ( is_home() || is_front_page() ) && $key_code === $original_language ) {
|
140 |
-
$link_button .= '?no_lredirect=true';
|
141 |
-
}
|
142 |
|
143 |
$button_html .= sprintf(
|
144 |
'<a data-wg-notranslate href="%s">%s</a>',
|
6 |
exit;
|
7 |
}
|
8 |
|
|
|
|
|
9 |
/**
|
10 |
* Button services
|
11 |
*
|
17 |
* @since 2.0
|
18 |
*/
|
19 |
public function __construct() {
|
20 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
21 |
+
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
22 |
+
$this->language_services = weglot_get_service( 'Language_Service_Weglot' );
|
23 |
+
$this->amp_services = weglot_get_service( 'Amp_Service_Weglot' );
|
24 |
+
$this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
|
25 |
+
$this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @since 2.3.0
|
30 |
+
* @return string
|
31 |
+
*/
|
32 |
+
public function get_flag_class() {
|
33 |
+
$options = $this->option_services->get_options();
|
34 |
+
$type_flags = $options['type_flags'];
|
35 |
+
$with_flags = $options['with_flags'];
|
36 |
+
|
37 |
+
$flag_class = $with_flags ? 'weglot-flags ' : '';
|
38 |
+
$flag_class .= '0' === $type_flags ? '' : 'flag-' . $type_flags . ' ';
|
39 |
+
|
40 |
+
return apply_filters( 'weglot_get_flag_class', $flag_class );
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @since 2.3.0
|
45 |
+
*
|
46 |
+
* @param LanguageEntry $language_entry
|
47 |
+
* @return string
|
48 |
+
*/
|
49 |
+
public function get_name_with_language_entry( $language_entry ) {
|
50 |
+
$options = $this->option_services->get_options();
|
51 |
+
$with_name = $options['with_name'];
|
52 |
+
$is_fullname = $options['is_fullname'];
|
53 |
+
$name = '';
|
54 |
+
|
55 |
+
if ( $with_name ) {
|
56 |
+
$name = ( $is_fullname ) ? $language_entry->getLocalName() : strtoupper( $language_entry->getIso639() );
|
57 |
+
}
|
58 |
+
|
59 |
+
return apply_filters( 'weglot_get_name_with_language_entry', $name, $language_entry );
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @since 2.3.0
|
64 |
+
*
|
65 |
+
* @return string
|
66 |
+
*/
|
67 |
+
public function get_class_dropdown() {
|
68 |
+
$options = $this->option_services->get_options();
|
69 |
+
$is_dropdown = $options['is_dropdown'];
|
70 |
+
$class = $is_dropdown ? 'weglot-dropdown ' : 'weglot-inline ';
|
71 |
+
|
72 |
+
return apply_filters( 'weglot_get_class_dropdown', $class );
|
73 |
}
|
74 |
|
75 |
|
76 |
+
|
77 |
/**
|
78 |
* Get html button switcher
|
79 |
*
|
80 |
* @since 2.0
|
81 |
+
* @version 2.3.0
|
82 |
* @return string
|
83 |
* @param string $add_class
|
84 |
*/
|
85 |
public function get_html( $add_class = '' ) {
|
86 |
+
$private_mode = $this->option_services->get_option( 'private_mode' );
|
87 |
+
$original_language = weglot_get_original_language();
|
88 |
+
|
89 |
+
$view_button = false;
|
90 |
+
foreach ($private_mode as $key_code => $value) {
|
91 |
+
if ( $key_code === $original_language || $key_code === 'active' ) {
|
92 |
+
continue;
|
93 |
+
}
|
94 |
+
|
95 |
+
if ( ! $this->private_language_services->is_active_private_mode_for_lang( $key_code ) ) {
|
96 |
+
$view_button = true;
|
97 |
+
}
|
98 |
+
}
|
99 |
+
if ( ! $view_button) {
|
100 |
+
return '';
|
101 |
}
|
102 |
|
103 |
+
$weglot_url = $this->request_url_services->get_weglot_url();
|
104 |
+
$amp_regex = $this->amp_services->get_regex( true );
|
105 |
+
$destination_language = weglot_get_destination_languages();
|
106 |
|
107 |
+
$current_language = $this->request_url_services->get_current_language( false );
|
|
|
108 |
|
109 |
+
if ( weglot_get_translate_amp_translation() && preg_match( '#' . $amp_regex . '#', $weglot_url->getUrl() ) === 1 ) {
|
110 |
+
$add_class .= ' weglot-invert';
|
111 |
+
}
|
112 |
|
113 |
+
$flag_class = $this->get_flag_class();
|
114 |
+
$class_aside = $this->get_class_dropdown();
|
115 |
|
116 |
$button_html = sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
|
117 |
$button_html .= sprintf( "<aside data-wg-notranslate class='country-selector %s'>", $class_aside . $add_class );
|
118 |
|
119 |
if ( ! empty( $original_language ) && ! empty( $destination_language ) ) {
|
120 |
+
$current_language_entry = $this->language_services->get_current_language_entry_from_key( $current_language );
|
121 |
+
$name = $this->get_name_with_language_entry( $current_language_entry );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
$uniq_id = 'wg' . uniqid( strtotime( 'now' ) ) . rand( 1, 1000 );
|
124 |
$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 );
|
128 |
array_unshift( $destination_language, $original_language );
|
129 |
|
130 |
foreach ( $destination_language as $key => $key_code ) {
|
131 |
+
if ( $key_code === $current_language || $this->private_language_services->is_active_private_mode_for_lang( $key_code ) ) {
|
132 |
continue;
|
133 |
}
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
$button_html .= sprintf( '<li class="wg-li %s" data-code-language="%s">', $flag_class . $key_code, $key_code );
|
136 |
|
137 |
+
$current_language_entry = $this->language_services->get_current_language_entry_from_key( $key_code );
|
138 |
+
$name = $this->get_name_with_language_entry( $current_language_entry );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
+
$link_button = $this->custom_url_services->get_link_button_with_key_code( $key_code );
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
$button_html .= sprintf(
|
143 |
'<a data-wg-notranslate href="%s">%s</a>',
|
src/services/class-custom-url-service-weglot.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WeglotWP\Services;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Custom URL services
|
11 |
+
*
|
12 |
+
* @since 2.3.0
|
13 |
+
*/
|
14 |
+
class Custom_Url_Service_Weglot {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @since 2.3.0
|
18 |
+
*/
|
19 |
+
public function __construct() {
|
20 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
21 |
+
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @since 2.3.0
|
26 |
+
* @param string $key_code
|
27 |
+
* @return string
|
28 |
+
*/
|
29 |
+
public function get_link( $key_code ) {
|
30 |
+
global $post;
|
31 |
+
$weglot_url = $this->request_url_services->get_weglot_url();
|
32 |
+
$request_without_language = array_filter( explode( '/', $weglot_url->getPath() ), 'strlen' );
|
33 |
+
$index_entries = count( $request_without_language );
|
34 |
+
$custom_urls = $this->option_services->get_option( 'custom_urls' );
|
35 |
+
$url_lang = $weglot_url->getForLanguage( $key_code );
|
36 |
+
$original_language = weglot_get_original_language();
|
37 |
+
|
38 |
+
$condition_test_custom_url = isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) && ! is_post_type_archive() && ! is_category() && ! is_tax() && ! is_archive();
|
39 |
+
|
40 |
+
if ( apply_filters( 'weglot_condition_test_custom_url', $condition_test_custom_url ) ) {
|
41 |
+
$slug_in_work = $request_without_language[ $index_entries ];
|
42 |
+
|
43 |
+
// Search from original slug
|
44 |
+
$key_slug = false;
|
45 |
+
if ( isset( $custom_urls[ $key_code ] ) && $post ) {
|
46 |
+
$key_slug = array_search( $post->post_name, $custom_urls[ $key_code ] ); //phpcs:ignore
|
47 |
+
}
|
48 |
+
if ( false !== $key_slug ) {
|
49 |
+
$url_lang = str_replace( $slug_in_work, $key_slug, $url_lang );
|
50 |
+
} else {
|
51 |
+
if ( $post ) {
|
52 |
+
$url_lang = str_replace( $slug_in_work, $post->post_name, $url_lang );
|
53 |
+
}
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
$link_button = apply_filters( 'weglot_link_language', $url_lang, $key_code );
|
58 |
+
|
59 |
+
$link_button = preg_replace( '#\?no_lredirect=true$#', '', $link_button ); // Remove ending "?no_lredirect=true"
|
60 |
+
|
61 |
+
return apply_filters( 'weglot_get_link_with_key_code', $link_button );
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @since 2.3.0
|
67 |
+
* @return string
|
68 |
+
* @param mixed $key_code
|
69 |
+
*/
|
70 |
+
public function get_link_button_with_key_code( $key_code ) {
|
71 |
+
$link_button = $this->get_link( $key_code );
|
72 |
+
|
73 |
+
if ( weglot_has_auto_redirect() && strpos( $link_button, 'no_lredirect' ) === false && ( is_home() || is_front_page() ) && $key_code === $original_language ) {
|
74 |
+
$link_button .= '?no_lredirect=true';
|
75 |
+
}
|
76 |
+
|
77 |
+
return apply_filters( 'weglot_get_link_button_with_key_code', $link_button );
|
78 |
+
}
|
79 |
+
}
|
src/services/class-email-translate-service-weglot.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WeglotWP\Services;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
|
10 |
+
use Weglot\Client\Client;
|
11 |
+
use Weglot\Parser\Parser;
|
12 |
+
use Weglot\Parser\ConfigProvider\ServerConfigProvider;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @since 2.3.0
|
16 |
+
*/
|
17 |
+
class Email_Translate_Service_Weglot {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* @since 2.3.0
|
21 |
+
*/
|
22 |
+
public function __construct() {
|
23 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Translate email with parser
|
29 |
+
* @version 2.3.0
|
30 |
+
* @param array $args
|
31 |
+
* @param string $language
|
32 |
+
* @return array
|
33 |
+
*/
|
34 |
+
public function translate_email( $args, $language ) {
|
35 |
+
$api_key = $this->option_services->get_option( 'api_key' );
|
36 |
+
|
37 |
+
if ( ! $api_key ) {
|
38 |
+
return $args;
|
39 |
+
}
|
40 |
+
|
41 |
+
try {
|
42 |
+
$original_language = weglot_get_original_language();
|
43 |
+
$exclude_blocks = $this->option_services->get_exclude_blocks();
|
44 |
+
|
45 |
+
$config = new ServerConfigProvider();
|
46 |
+
$client = new Client( $api_key );
|
47 |
+
$parser = new Parser( $client, $config, $exclude_blocks );
|
48 |
+
$translated_subject = $parser->translate( '<p>' . $args['subject'] . '</p>', $original_language, $language ); //phpcs:ignore
|
49 |
+
|
50 |
+
$config = new ServerConfigProvider();
|
51 |
+
$client = new Client( $api_key );
|
52 |
+
$parser = new Parser( $client, $config, $exclude_blocks );
|
53 |
+
$translated_message = $parser->translate( $args['message'], $original_language, $language ); //phpcs:ignore
|
54 |
+
|
55 |
+
return [
|
56 |
+
'subject' => $translated_subject,
|
57 |
+
'message' => $translated_message,
|
58 |
+
];
|
59 |
+
} catch ( \Exception $e ) {
|
60 |
+
return $args;
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
|
66 |
+
|
src/services/class-generate-switcher-service-weglot.php
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WeglotWP\Services;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
*
|
11 |
+
* @since 2.3.0
|
12 |
+
*/
|
13 |
+
class Generate_Switcher_Service_Weglot {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @since 2.3.0
|
17 |
+
*/
|
18 |
+
public function __construct() {
|
19 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
20 |
+
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
21 |
+
$this->language_services = weglot_get_service( 'Language_Service_Weglot' );
|
22 |
+
$this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
|
23 |
+
$this->button_services = weglot_get_service( 'Button_Service_Weglot' );
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* @since 2.3.0
|
28 |
+
*
|
29 |
+
* @param string $dom
|
30 |
+
* @return string
|
31 |
+
*/
|
32 |
+
public function replace_div_id( $dom ) {
|
33 |
+
if ( strpos( $dom, '<div id="weglot_here"></div>' ) === false ) {
|
34 |
+
return $dom;
|
35 |
+
}
|
36 |
+
|
37 |
+
$button_html = $this->button_services->get_html( 'weglot-shortcode' );
|
38 |
+
$dom = str_replace( '<div id="weglot_here"></div>', $button_html, $dom );
|
39 |
+
|
40 |
+
return apply_filters( 'weglot_replace_div_id', $dom );
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @since 2.3.0
|
45 |
+
*
|
46 |
+
* @param string $dom
|
47 |
+
* @return string
|
48 |
+
*/
|
49 |
+
public function replace_weglot_menu( $dom ) {
|
50 |
+
if ( strpos( $dom, '[weglot_menu' ) === false ) {
|
51 |
+
return $dom;
|
52 |
+
}
|
53 |
+
|
54 |
+
$languages_configured = $this->language_services->get_languages_configured();
|
55 |
+
$options = $this->option_services->get_options();
|
56 |
+
$is_fullname = $options['is_fullname'];
|
57 |
+
$with_name = $options['with_name'];
|
58 |
+
|
59 |
+
$url = $this->request_url_services->get_weglot_url();
|
60 |
+
|
61 |
+
foreach ( $languages_configured as $language ) {
|
62 |
+
$shortcode_title = sprintf( '\[weglot_menu_title-%s\]', $language->getIso639() );
|
63 |
+
$shortcode_title_without_bracket = sprintf( 'weglot_menu_title-%s', $language->getIso639() );
|
64 |
+
$shortcode_title_html = str_replace( '\[', '%5B', $shortcode_title );
|
65 |
+
$shortcode_title_html = str_replace( '\]', '%5D', $shortcode_title_html );
|
66 |
+
$shortcode_url = sprintf( '(http|https):\/\/\[weglot_menu_current_url-%s\]', $language->getIso639() );
|
67 |
+
$shortcode_url_html = str_replace( '\[', '%5B', $shortcode_url );
|
68 |
+
$shortcode_url_html = str_replace( '\]', '%5D', $shortcode_url_html );
|
69 |
+
|
70 |
+
$name = $this->button_services->get_name_with_language_entry( $language );
|
71 |
+
|
72 |
+
$dom = preg_replace( '#' . $shortcode_title . '#i', $name, $dom );
|
73 |
+
$dom = preg_replace( '#' . $shortcode_title_html . '#i', $name, $dom );
|
74 |
+
$dom = preg_replace( '#' . $shortcode_title_without_bracket . '#i', $name, $dom );
|
75 |
+
|
76 |
+
$link_menu = $this->custom_url_services->get_link_button_with_key_code( $language->getIso639() );
|
77 |
+
|
78 |
+
// Compatibility Menu HTTPS if not work. Since 2.0.6
|
79 |
+
if (
|
80 |
+
(
|
81 |
+
is_ssl() ||
|
82 |
+
isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] // phpcs:ignore
|
83 |
+
) &&
|
84 |
+
strpos( $link_menu, 'https://' ) === false
|
85 |
+
) {
|
86 |
+
$link_menu = str_replace( 'http', 'https', $link_menu );
|
87 |
+
}
|
88 |
+
|
89 |
+
$dom = preg_replace( '#' . $shortcode_url . '#i', $link_menu, $dom );
|
90 |
+
$dom = preg_replace( '#' . $shortcode_url_html . '#i', $link_menu, $dom );
|
91 |
+
}
|
92 |
+
|
93 |
+
$dom .= sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
|
94 |
+
|
95 |
+
return apply_filters( 'weglot_replace_weglot_menu', $dom );
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @since 2.3.0
|
100 |
+
*
|
101 |
+
* @param string $dom
|
102 |
+
* @return string
|
103 |
+
*/
|
104 |
+
public function render_default_button( $dom ) {
|
105 |
+
if ( strpos( $dom, sprintf( '<!--Weglot %s-->', WEGLOT_VERSION ) ) !== false ) {
|
106 |
+
return $dom;
|
107 |
+
}
|
108 |
+
|
109 |
+
// Place the button if not in the page
|
110 |
+
$button_html = $this->button_services->get_html( 'weglot-default' );
|
111 |
+
$dom = ( strpos( $dom, '</body>' ) !== false) ? str_replace( '</body>', $button_html . ' </body>', $dom ) : str_replace( '</footer>', $button_html . ' </footer>', $dom );
|
112 |
+
|
113 |
+
return apply_filters( 'weglot_render_default_button', $dom );
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* @since 2.3.0
|
118 |
+
* @param string $dom
|
119 |
+
* @return string
|
120 |
+
*/
|
121 |
+
public function generate_switcher_from_dom( $dom ) {
|
122 |
+
$dom = $this->replace_div_id( $dom );
|
123 |
+
$dom = $this->replace_weglot_menu( $dom );
|
124 |
+
$dom = $this->render_default_button( $dom );
|
125 |
+
|
126 |
+
return apply_filters( 'weglot_generate_switcher_from_dom', $dom );
|
127 |
+
}
|
128 |
+
}
|
src/services/class-href-lang-service-weglot.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WeglotWP\Services;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @since 2.3.0
|
11 |
+
*/
|
12 |
+
class Href_Lang_Service_Weglot {
|
13 |
+
protected $languages = null;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @since 2.3.0
|
17 |
+
*/
|
18 |
+
public function __construct() {
|
19 |
+
$this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
|
20 |
+
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
21 |
+
$this->private_language_service = weglot_get_service( 'Private_Language_Service_Weglot' );
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @since 2.3.0
|
26 |
+
*/
|
27 |
+
public function generate_href_lang_tags() {
|
28 |
+
$destination_languages = weglot_get_all_languages_configured();
|
29 |
+
$render = '';
|
30 |
+
try {
|
31 |
+
foreach ( $destination_languages as $language ) {
|
32 |
+
if ( $this->private_language_service->is_active_private_mode_for_lang( $language ) ) {
|
33 |
+
continue;
|
34 |
+
}
|
35 |
+
|
36 |
+
$url = $this->custom_url_services->get_link( $language );
|
37 |
+
$render .= '<link rel="alternate" href="' . $url . '" hreflang="' . $language . '"/>' . "\n";
|
38 |
+
}
|
39 |
+
} catch ( \Exception $e ) {
|
40 |
+
$render = $this->request_url_services->get_weglot_url()->generateHrefLangsTags();
|
41 |
+
}
|
42 |
+
|
43 |
+
return apply_filters( 'weglot_href_lang', $render );
|
44 |
+
}
|
45 |
+
}
|
src/services/class-language-service-weglot.php
CHANGED
@@ -105,4 +105,25 @@ class Language_Service_Weglot {
|
|
105 |
|
106 |
return $languages_object;
|
107 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
}
|
105 |
|
106 |
return $languages_object;
|
107 |
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* @since 2.3.0
|
111 |
+
*
|
112 |
+
* @param string $key_code
|
113 |
+
* @return LanguageEntry
|
114 |
+
*/
|
115 |
+
public function get_current_language_entry_from_key( $key_code ) {
|
116 |
+
$languages = $this->get_languages_available();
|
117 |
+
|
118 |
+
if ( isset( $languages[ $key_code ] ) ) {
|
119 |
+
$current_language_entry = $languages[ $key_code ];
|
120 |
+
} else {
|
121 |
+
$current_language_entry = apply_filters( 'weglot_current_language_entry', $key_code );
|
122 |
+
if ( $current_language_entry === $key_code ) {
|
123 |
+
throw new \Exception( 'You need create a language entry' );
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
return $current_language_entry;
|
128 |
+
}
|
129 |
}
|
src/services/class-migration-service-weglot.php
CHANGED
@@ -75,5 +75,28 @@ class Migration_Service_Weglot {
|
|
75 |
$this->option_services->set_options( $new_options );
|
76 |
update_option( 'weglot_version', WEGLOT_VERSION );
|
77 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
|
75 |
$this->option_services->set_options( $new_options );
|
76 |
update_option( 'weglot_version', WEGLOT_VERSION );
|
77 |
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Update 2.2.0 > 2.3.0
|
81 |
+
* @since 2.3.0
|
82 |
+
* @return void
|
83 |
+
*/
|
84 |
+
public function update_v230() {
|
85 |
+
$private_mode = weglot_get_option( 'private_mode' );
|
86 |
+
|
87 |
+
if ( $private_mode ) {
|
88 |
+
$destination_language = weglot_get_destination_language();
|
89 |
+
$new_options = weglot_get_options();
|
90 |
+
$new_options['private_mode'] = [];
|
91 |
+
$new_options['private_mode']['active'] = true;
|
92 |
+
|
93 |
+
foreach ( $destination_language as $key => $lang ) {
|
94 |
+
$new_options['private_mode'][ $lang ] = true;
|
95 |
+
}
|
96 |
+
|
97 |
+
$this->option_services->set_options( $new_options );
|
98 |
+
update_option( 'weglot_version', WEGLOT_VERSION );
|
99 |
+
}
|
100 |
+
}
|
101 |
}
|
102 |
|
src/services/class-multisite-service-weglot.php
CHANGED
@@ -30,7 +30,7 @@ class Multisite_Service_Weglot {
|
|
30 |
$paths = [];
|
31 |
|
32 |
if ( is_multisite() ) {
|
33 |
-
$sites = get_sites( [
|
34 |
'number' => 0,
|
35 |
] );
|
36 |
|
30 |
$paths = [];
|
31 |
|
32 |
if ( is_multisite() ) {
|
33 |
+
$sites = \get_sites( [
|
34 |
'number' => 0,
|
35 |
] );
|
36 |
|
src/services/class-network-service-weglot.php
DELETED
@@ -1,63 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WeglotWP\Services;
|
4 |
-
|
5 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
-
exit;
|
7 |
-
}
|
8 |
-
|
9 |
-
/**
|
10 |
-
* Network service
|
11 |
-
*
|
12 |
-
* @since 2.0
|
13 |
-
*/
|
14 |
-
class Network_Service_Weglot {
|
15 |
-
|
16 |
-
/**
|
17 |
-
* @since 2.0
|
18 |
-
* @var array|null
|
19 |
-
*/
|
20 |
-
protected $networks = null;
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @since 2.0
|
24 |
-
*/
|
25 |
-
public function __construct() {
|
26 |
-
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
27 |
-
}
|
28 |
-
|
29 |
-
/**
|
30 |
-
* @since 2.0
|
31 |
-
*
|
32 |
-
* @return Network_Service_Weglot
|
33 |
-
*/
|
34 |
-
public function set_networks() {
|
35 |
-
if ( is_multisite() ) {
|
36 |
-
$sites = get_sites( [
|
37 |
-
'number' => 0,
|
38 |
-
] );
|
39 |
-
|
40 |
-
foreach ( $sites as $site ) {
|
41 |
-
$path = $site->path;
|
42 |
-
array_push( $this->networks, $path );
|
43 |
-
}
|
44 |
-
} else {
|
45 |
-
array_push( $this->networks, $this->request_url_services->get_home_wordpress_directory() . '/' );
|
46 |
-
}
|
47 |
-
|
48 |
-
return $this;
|
49 |
-
}
|
50 |
-
|
51 |
-
|
52 |
-
/**
|
53 |
-
* @since 2.0
|
54 |
-
* @return array
|
55 |
-
*/
|
56 |
-
public function get_networks() {
|
57 |
-
if ( null === $this->networks ) {
|
58 |
-
$this->set_networks();
|
59 |
-
}
|
60 |
-
|
61 |
-
return $this->networks;
|
62 |
-
}
|
63 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/services/class-option-service-weglot.php
CHANGED
@@ -37,7 +37,9 @@ class Option_Service_Weglot {
|
|
37 |
'allowed' => true,
|
38 |
'custom_urls' => [],
|
39 |
'flag_css' => '',
|
40 |
-
'private_mode' =>
|
|
|
|
|
41 |
];
|
42 |
|
43 |
/**
|
@@ -52,10 +54,11 @@ class Option_Service_Weglot {
|
|
52 |
|
53 |
/**
|
54 |
* @since 2.0
|
|
|
55 |
* @return array
|
56 |
*/
|
57 |
public function get_options() {
|
58 |
-
return wp_parse_args( get_option( WEGLOT_SLUG ), $this->get_options_default() );
|
59 |
}
|
60 |
|
61 |
/**
|
@@ -101,6 +104,8 @@ class Option_Service_Weglot {
|
|
101 |
public function get_exclude_urls() {
|
102 |
$exclude_urls = $this->get_option( 'exclude_urls' );
|
103 |
$exclude_urls[] = '/wp-login.php';
|
|
|
|
|
104 |
|
105 |
return apply_filters( 'weglot_exclude_urls', $exclude_urls );
|
106 |
}
|
37 |
'allowed' => true,
|
38 |
'custom_urls' => [],
|
39 |
'flag_css' => '',
|
40 |
+
'private_mode' => [
|
41 |
+
'active' => false,
|
42 |
+
],
|
43 |
];
|
44 |
|
45 |
/**
|
54 |
|
55 |
/**
|
56 |
* @since 2.0
|
57 |
+
* @version 2.2.2
|
58 |
* @return array
|
59 |
*/
|
60 |
public function get_options() {
|
61 |
+
return apply_filters( 'weglot_get_options', wp_parse_args( get_option( WEGLOT_SLUG ), $this->get_options_default() ) );
|
62 |
}
|
63 |
|
64 |
/**
|
104 |
public function get_exclude_urls() {
|
105 |
$exclude_urls = $this->get_option( 'exclude_urls' );
|
106 |
$exclude_urls[] = '/wp-login.php';
|
107 |
+
$exclude_urls[] = '/sitemaps_xsl.xsl';
|
108 |
+
$exclude_urls[] = '/sitemaps.xml';
|
109 |
|
110 |
return apply_filters( 'weglot_exclude_urls', $exclude_urls );
|
111 |
}
|
src/services/class-parser-service-weglot.php
CHANGED
@@ -10,6 +10,7 @@ use Weglot\Parser\Parser;
|
|
10 |
use Weglot\Util\Url;
|
11 |
use Weglot\Util\Server;
|
12 |
use Weglot\Parser\ConfigProvider\ServerConfigProvider;
|
|
|
13 |
|
14 |
if ( ! defined( 'ABSPATH' ) ) {
|
15 |
exit;
|
@@ -40,6 +41,7 @@ class Parser_Service_Weglot {
|
|
40 |
|
41 |
/**
|
42 |
* @since 2.0
|
|
|
43 |
* @return array
|
44 |
*/
|
45 |
public function get_parser() {
|
@@ -51,15 +53,21 @@ class Parser_Service_Weglot {
|
|
51 |
}
|
52 |
|
53 |
$api_key = $this->option_services->get_option( 'api_key' );
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
$config = new ServerConfigProvider();
|
56 |
-
$client = new Client( $api_key );
|
57 |
if ( '2' === WEGLOT_LIB_PARSER ) {
|
58 |
$listeners = $this->dom_listeners_services->get_dom_listeners();
|
59 |
$parser = new Parser( $client, $config, $exclude_blocks, $listeners );
|
60 |
} else {
|
61 |
$parser = new Parser( $client, $config, $exclude_blocks );
|
62 |
$parser->getDomCheckerProvider()->addCheckers( $this->dom_checkers_services->get_dom_checkers() );
|
|
|
|
|
|
|
63 |
}
|
64 |
|
65 |
return $parser;
|
10 |
use Weglot\Util\Url;
|
11 |
use Weglot\Util\Server;
|
12 |
use Weglot\Parser\ConfigProvider\ServerConfigProvider;
|
13 |
+
use Weglot\Parser\ConfigProvider\ConfigProviderInterface;
|
14 |
|
15 |
if ( ! defined( 'ABSPATH' ) ) {
|
16 |
exit;
|
41 |
|
42 |
/**
|
43 |
* @since 2.0
|
44 |
+
* @version 2.2.2
|
45 |
* @return array
|
46 |
*/
|
47 |
public function get_parser() {
|
53 |
}
|
54 |
|
55 |
$api_key = $this->option_services->get_option( 'api_key' );
|
56 |
+
$config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
|
57 |
+
if ( ! ( $config instanceof ConfigProviderInterface ) ) {
|
58 |
+
$config = new ServerConfigProvider();
|
59 |
+
}
|
60 |
+
$client = new Client( $api_key );
|
61 |
|
|
|
|
|
62 |
if ( '2' === WEGLOT_LIB_PARSER ) {
|
63 |
$listeners = $this->dom_listeners_services->get_dom_listeners();
|
64 |
$parser = new Parser( $client, $config, $exclude_blocks, $listeners );
|
65 |
} else {
|
66 |
$parser = new Parser( $client, $config, $exclude_blocks );
|
67 |
$parser->getDomCheckerProvider()->addCheckers( $this->dom_checkers_services->get_dom_checkers() );
|
68 |
+
$ignored_nodes = apply_filters( 'weglot_get_parser_ignored_nodes', $parser->getIgnoredNodesFormatter()->getIgnoredNodes() );
|
69 |
+
|
70 |
+
$parser->getIgnoredNodesFormatter()->setIgnoredNodes( $ignored_nodes );
|
71 |
}
|
72 |
|
73 |
return $parser;
|
src/services/class-private-language-service-weglot.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WeglotWP\Services;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
use Weglot\Util\Url;
|
10 |
+
use Weglot\Util\Server;
|
11 |
+
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Private_Language_Service_Weglot
|
15 |
+
*
|
16 |
+
* @since 2.3.0
|
17 |
+
*/
|
18 |
+
class Private_Language_Service_Weglot {
|
19 |
+
protected $role_private_mode = 'administrator';
|
20 |
+
|
21 |
+
/**
|
22 |
+
* @since 2.3.0
|
23 |
+
*/
|
24 |
+
public function __construct() {
|
25 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @since 2.3.0
|
30 |
+
*
|
31 |
+
* @param string $key_lang
|
32 |
+
* @return boolean
|
33 |
+
*/
|
34 |
+
public function is_active_private_mode_for_lang( $key_lang ) {
|
35 |
+
$private_mode_languages = $this->option_services->get_option( 'private_mode' );
|
36 |
+
if ( ! $private_mode_languages['active'] ) {
|
37 |
+
return false;
|
38 |
+
}
|
39 |
+
|
40 |
+
unset( $private_mode_languages['active'] );
|
41 |
+
foreach ( $private_mode_languages as $lang => $lang_active ) {
|
42 |
+
if ( $key_lang === $lang && $lang_active && ! current_user_can( $this->role_private_mode ) ) {
|
43 |
+
return true;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
return false;
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
|
src/services/class-redirect-service-weglot.php
CHANGED
@@ -35,6 +35,7 @@ class Redirect_Service_Weglot {
|
|
35 |
public function __construct() {
|
36 |
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
37 |
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
|
|
38 |
}
|
39 |
|
40 |
/**
|
@@ -46,25 +47,50 @@ class Redirect_Service_Weglot {
|
|
46 |
return $this->no_redirect;
|
47 |
}
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
/**
|
50 |
* @since 2.0
|
51 |
-
*
|
52 |
* @return string
|
53 |
*/
|
54 |
public function auto_redirect() {
|
55 |
-
if ( ! isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { //phpcs:ignore
|
56 |
return;
|
57 |
}
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
$destination_languages = weglot_get_destination_languages();
|
61 |
|
62 |
if (
|
63 |
in_array( $server_lang, $destination_languages ) && // phpcs:ignore
|
64 |
-
weglot_get_original_language() === $this->request_url_services->get_current_language()
|
|
|
65 |
) {
|
66 |
$url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $server_lang ) );
|
67 |
-
|
68 |
exit();
|
69 |
}
|
70 |
}
|
35 |
public function __construct() {
|
36 |
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
37 |
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
38 |
+
$this->private_services = weglot_get_service( 'Private_Language_Service_Weglot' );
|
39 |
}
|
40 |
|
41 |
/**
|
47 |
return $this->no_redirect;
|
48 |
}
|
49 |
|
50 |
+
/**
|
51 |
+
* @since 2.3.0
|
52 |
+
* @param string $server_lang
|
53 |
+
* @return string
|
54 |
+
*/
|
55 |
+
protected function language_exception( $server_lang ) {
|
56 |
+
if ( in_array( $server_lang, ['nb', 'nn', ] ) ) { //phpcs:ignore
|
57 |
+
// Case Norwegian
|
58 |
+
$server_lang = 'no';
|
59 |
+
}
|
60 |
+
|
61 |
+
return apply_filters( 'weglot_redirection_language_exception', $server_lang );
|
62 |
+
}
|
63 |
+
|
64 |
/**
|
65 |
* @since 2.0
|
66 |
+
* @version 2.3.0
|
67 |
* @return string
|
68 |
*/
|
69 |
public function auto_redirect() {
|
70 |
+
if ( ! isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) && ! isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { //phpcs:ignore
|
71 |
return;
|
72 |
}
|
73 |
|
74 |
+
if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { //phpcs:ignore
|
75 |
+
$server_lang = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 ); //phpcs:ignore
|
76 |
+
} else {
|
77 |
+
if ( isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { // phpcs:ignore
|
78 |
+
// Compatibility Cloudfare
|
79 |
+
$server_lang = strtolower( $_SERVER['HTTP_CF_IPCOUNTRY'] ); //phpcs:ignore
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
$server_lang = $this->language_exception( $server_lang );
|
84 |
+
|
85 |
$destination_languages = weglot_get_destination_languages();
|
86 |
|
87 |
if (
|
88 |
in_array( $server_lang, $destination_languages ) && // phpcs:ignore
|
89 |
+
weglot_get_original_language() === $this->request_url_services->get_current_language() &&
|
90 |
+
! $this->private_services->is_active_private_mode_for_lang( $server_lang )
|
91 |
) {
|
92 |
$url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $server_lang ) );
|
93 |
+
header( "Location: $url_auto_redirect", true, 302 );
|
94 |
exit();
|
95 |
}
|
96 |
}
|
src/services/class-replace-link-service-weglot.php
CHANGED
@@ -48,6 +48,7 @@ class Replace_Link_Service_Weglot {
|
|
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
|
48 |
$request_without_language = array_filter( explode( '/', $path ), 'strlen' );
|
49 |
$index_entries = count( $request_without_language );
|
50 |
|
51 |
+
|
52 |
if ( isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) && isset( $custom_urls[ $current_language ] ) ) {
|
53 |
$slug_in_work = $request_without_language[ $index_entries ];
|
54 |
$key_slug = array_search( $slug_in_work, $custom_urls[ $current_language ] ); //phpcs:ignore
|
src/services/class-replace-url-service-weglot.php
CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
6 |
exit;
|
7 |
}
|
8 |
|
|
|
9 |
|
10 |
/**
|
11 |
* Replace URL
|
@@ -22,6 +23,26 @@ class Replace_Url_Service_Weglot {
|
|
22 |
$this->replace_link_service = weglot_get_service( 'Replace_Link_Service_Weglot' );
|
23 |
}
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
/**
|
26 |
* Replace link
|
27 |
*
|
@@ -32,7 +53,6 @@ class Replace_Url_Service_Weglot {
|
|
32 |
*/
|
33 |
public function modify_link( $pattern, $translated_page, $type ) {
|
34 |
$current_language = weglot_get_current_language();
|
35 |
-
|
36 |
preg_match_all( $pattern, $translated_page, $out, PREG_PATTERN_ORDER );
|
37 |
$count_out_0 = count( $out[0] );
|
38 |
for ( $i = 0;$i < $count_out_0; $i++ ) {
|
@@ -47,7 +67,7 @@ class Replace_Url_Service_Weglot {
|
|
47 |
continue;
|
48 |
}
|
49 |
|
50 |
-
if (
|
51 |
continue;
|
52 |
}
|
53 |
|
@@ -82,10 +102,10 @@ class Replace_Url_Service_Weglot {
|
|
82 |
public function check_link( $current_url, $sometags = null, $sometags2 = null ) {
|
83 |
$admin_url = admin_url();
|
84 |
$parsed_url = wp_parse_url( $current_url );
|
85 |
-
|
86 |
return (
|
87 |
(
|
88 |
-
( $current_url[0]
|
89 |
( isset( $current_url[0] ) && $current_url[0] === '/' && ( isset( $current_url[1] ) ) && '/' !== $current_url[1] ) //phpcs:ignore
|
90 |
) &&
|
91 |
strpos( $current_url, $admin_url ) === false
|
6 |
exit;
|
7 |
}
|
8 |
|
9 |
+
use WeglotWP\Helpers\Helper_Replace_Url_Weglot;
|
10 |
|
11 |
/**
|
12 |
* Replace URL
|
23 |
$this->replace_link_service = weglot_get_service( 'Replace_Link_Service_Weglot' );
|
24 |
}
|
25 |
|
26 |
+
/**
|
27 |
+
* @since 2.3.0
|
28 |
+
*
|
29 |
+
* @param string $dom
|
30 |
+
* @return string
|
31 |
+
*/
|
32 |
+
public function replace_link_in_dom( $dom ) {
|
33 |
+
$data = Helper_Replace_Url_Weglot::get_replace_modify_link();
|
34 |
+
|
35 |
+
foreach ( $data as $key => $value ) {
|
36 |
+
$dom = $this->modify_link( $value, $dom, $key );
|
37 |
+
}
|
38 |
+
|
39 |
+
$current_language = weglot_get_current_language();
|
40 |
+
$dom = preg_replace( '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/', '<html $1lang=$2' . $current_language . '$4', $dom );
|
41 |
+
$dom = preg_replace( '/property="og:locale" content=(\"|\')(\S*)(\"|\')/', 'property="og:locale" content=$1' . $current_language . '$3', $dom );
|
42 |
+
|
43 |
+
return apply_filters( 'weglot_replace_link', $dom );
|
44 |
+
}
|
45 |
+
|
46 |
/**
|
47 |
* Replace link
|
48 |
*
|
53 |
*/
|
54 |
public function modify_link( $pattern, $translated_page, $type ) {
|
55 |
$current_language = weglot_get_current_language();
|
|
|
56 |
preg_match_all( $pattern, $translated_page, $out, PREG_PATTERN_ORDER );
|
57 |
$count_out_0 = count( $out[0] );
|
58 |
for ( $i = 0;$i < $count_out_0; $i++ ) {
|
67 |
continue;
|
68 |
}
|
69 |
|
70 |
+
if ( ! $this->check_link( $current_url, $sometags, $sometags2 ) ) {
|
71 |
continue;
|
72 |
}
|
73 |
|
102 |
public function check_link( $current_url, $sometags = null, $sometags2 = null ) {
|
103 |
$admin_url = admin_url();
|
104 |
$parsed_url = wp_parse_url( $current_url );
|
105 |
+
$server_host = apply_filters( 'weglot_check_link_server_host', $_SERVER['HTTP_HOST'] ); //phpcs:ignore
|
106 |
return (
|
107 |
(
|
108 |
+
( 'h' === $current_url[0] && $parsed_url['host'] === $server_host ) ||
|
109 |
( isset( $current_url[0] ) && $current_url[0] === '/' && ( isset( $current_url[1] ) ) && '/' !== $current_url[1] ) //phpcs:ignore
|
110 |
) &&
|
111 |
strpos( $current_url, $admin_url ) === false
|
src/services/class-translate-service-weglot.php
ADDED
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WeglotWP\Services;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
use WeglotWP\Helpers\Helper_Json_Inline_Weglot;
|
10 |
+
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @since 2.3.0
|
14 |
+
*/
|
15 |
+
class Translate_Service_Weglot {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @since 2.3.0
|
19 |
+
*/
|
20 |
+
public function __construct() {
|
21 |
+
$this->option_services = weglot_get_service( 'Option_Service_Weglot' );
|
22 |
+
$this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
|
23 |
+
$this->replace_url_services = weglot_get_service( 'Replace_Url_Service_Weglot' );
|
24 |
+
$this->replace_link_services = weglot_get_service( 'Replace_Link_Service_Weglot' );
|
25 |
+
$this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
|
26 |
+
$this->wc_active_services = weglot_get_service( 'WC_Active_Weglot' );
|
27 |
+
$this->other_translate_services = weglot_get_service( 'Other_Translate_Service_Weglot' );
|
28 |
+
$this->generate_switcher_service = weglot_get_service( 'Generate_Switcher_Service_Weglot' );
|
29 |
+
}
|
30 |
+
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @since 2.3.0
|
34 |
+
* @return void
|
35 |
+
*/
|
36 |
+
public function weglot_translate() {
|
37 |
+
$this->set_original_language( weglot_get_original_language() );
|
38 |
+
$this->set_current_language( $this->request_url_services->get_current_language() );
|
39 |
+
ob_start( [ $this, 'weglot_treat_page' ] );
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @since 2.3.0
|
44 |
+
* @param string $current_language
|
45 |
+
*/
|
46 |
+
public function set_current_language( $current_language ) {
|
47 |
+
$this->current_language = $current_language;
|
48 |
+
return $this;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @since 2.3.0
|
53 |
+
* @param string $original_language
|
54 |
+
*/
|
55 |
+
public function set_original_language( $original_language ) {
|
56 |
+
$this->original_language = $original_language;
|
57 |
+
return $this;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @see weglot_init / ob_start
|
62 |
+
* @since 2.3.0
|
63 |
+
* @param string $content
|
64 |
+
* @return string
|
65 |
+
*/
|
66 |
+
public function weglot_treat_page( $content ) {
|
67 |
+
$this->set_current_language( $this->request_url_services->get_current_language() ); // Need to reset
|
68 |
+
|
69 |
+
$allowed = $this->option_services->get_option( 'allowed' );
|
70 |
+
// Choose type translate
|
71 |
+
$type = ( Helper_Json_Inline_Weglot::is_json( $content ) ) ? 'json' : 'html';
|
72 |
+
$type = apply_filters( 'weglot_type_treat_page', $type );
|
73 |
+
|
74 |
+
if ( ! $allowed ) {
|
75 |
+
$content = $this->weglot_render_dom( $content );
|
76 |
+
if ( 'json' === $type || wp_doing_ajax() ) {
|
77 |
+
return $content;
|
78 |
+
}
|
79 |
+
|
80 |
+
return $content . '<!--Not allowed-->';
|
81 |
+
}
|
82 |
+
|
83 |
+
$active_translation = apply_filters( 'weglot_active_translation', true );
|
84 |
+
|
85 |
+
// No need to translate but prepare new dom with button
|
86 |
+
if ( $this->current_language === $this->original_language || ! $active_translation ) {
|
87 |
+
return $this->weglot_render_dom( $content );
|
88 |
+
}
|
89 |
+
|
90 |
+
$parser = $this->parser_services->get_parser();
|
91 |
+
|
92 |
+
try {
|
93 |
+
switch ( $type ) {
|
94 |
+
case 'json':
|
95 |
+
$json = \json_decode( $content, true );
|
96 |
+
$content = $this->translate_array( $json );
|
97 |
+
$content = $this->replace_link_array( $content );
|
98 |
+
$content = apply_filters( 'weglot_json_treat_page', $content );
|
99 |
+
|
100 |
+
return wp_json_encode( $content );
|
101 |
+
case 'html':
|
102 |
+
$content = $this->fix_menu_link( $content );
|
103 |
+
$translated_content = $parser->translate( $content, $this->original_language, $this->current_language ); // phpcs:ignore
|
104 |
+
|
105 |
+
if ( $this->wc_active_services->is_active() ) {
|
106 |
+
// Improve this with multiple service
|
107 |
+
$translated_content = weglot_get_service( 'WC_Translate_Weglot' )->translate_words( $translated_content );
|
108 |
+
}
|
109 |
+
|
110 |
+
$translated_content = $this->other_translate_services->translate_words( $translated_content );
|
111 |
+
|
112 |
+
$translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
|
113 |
+
|
114 |
+
return $this->weglot_render_dom( $translated_content );
|
115 |
+
default:
|
116 |
+
$name_filter = sprintf( 'weglot_%s_treat_page', $type );
|
117 |
+
return apply_filters( $name_filter, $content, $parser, $this->original_language, $this->current_language );
|
118 |
+
|
119 |
+
}
|
120 |
+
} catch ( ApiError $e ) {
|
121 |
+
if ( 'json' !== $type ) {
|
122 |
+
$content .= '<!--Weglot error API : ' . $this->remove_comments( $e->getMessage() ) . '-->';
|
123 |
+
}
|
124 |
+
if ( strpos( $e->getMessage(), 'NMC' ) !== false ) {
|
125 |
+
$this->option_services->set_option_by_key( 'allowed', false );
|
126 |
+
}
|
127 |
+
return $content;
|
128 |
+
} catch ( \Exception $e ) {
|
129 |
+
if ( 'json' !== $type ) {
|
130 |
+
$content .= '<!--Weglot error : ' . $this->remove_comments( $e->getMessage() ) . '-->';
|
131 |
+
}
|
132 |
+
return $content;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* @since 2.3.0
|
138 |
+
*
|
139 |
+
* @param array $array
|
140 |
+
* @return array
|
141 |
+
*/
|
142 |
+
public function translate_array( $array ) {
|
143 |
+
$array_not_ajax_html = apply_filters( 'weglot_array_not_ajax_html', [ 'redirecturl', 'url' ] );
|
144 |
+
foreach ( $array as $key => $val ) {
|
145 |
+
if ( is_array( $val ) ) {
|
146 |
+
$array[ $key ] = $this->translate_array( $val );
|
147 |
+
} else {
|
148 |
+
if ( $this->is_ajax_html( $val ) ) {
|
149 |
+
try {
|
150 |
+
$parser = $this->parser_services->get_parser();
|
151 |
+
$array[ $key ] = $parser->translate( $val, $this->original_language, $this->current_language ); //phpcs:ignore
|
152 |
+
} catch ( \Exception $e ) {
|
153 |
+
continue;
|
154 |
+
}
|
155 |
+
} elseif ( in_array( $key, $array_not_ajax_html ) ) { //phpcs:ignore
|
156 |
+
$array[$key] = $this->replace_link_services->replace_url( $val ); //phpcs:ignore
|
157 |
+
}
|
158 |
+
}
|
159 |
+
}
|
160 |
+
return $array;
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Replace links for JSON translate
|
165 |
+
*
|
166 |
+
* @since 2.3.0
|
167 |
+
*
|
168 |
+
* @param array $array
|
169 |
+
* @return array
|
170 |
+
*/
|
171 |
+
public function replace_link_array( $array ) {
|
172 |
+
$array_not_ajax_html = apply_filters( 'weglot_array_not_ajax_html', [ 'redirecturl', 'url' ] );
|
173 |
+
|
174 |
+
foreach ( $array as $key => $val ) {
|
175 |
+
if ( is_array( $val ) ) {
|
176 |
+
$array[ $key ] = $this->replace_link_array( $val );
|
177 |
+
} else {
|
178 |
+
if ( $this->is_ajax_html( $val ) ) {
|
179 |
+
$array[ $key ] = $this->replace_url_services->replace_link_in_dom( $val );
|
180 |
+
}
|
181 |
+
}
|
182 |
+
}
|
183 |
+
|
184 |
+
return $array;
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* @since 2.3.0
|
189 |
+
*
|
190 |
+
* @param string $string
|
191 |
+
* @return boolean
|
192 |
+
*/
|
193 |
+
protected function is_ajax_html( $string ) {
|
194 |
+
$preg_match_ajax_html = apply_filters( 'weglot_is_ajax_html_regex', '/<(a|div|span|p|i|aside|input|textarea|select|h1|h2|h3|h4|meta|button|form|li|strong|ul|option)/' );
|
195 |
+
$result = preg_match_all( $preg_match_ajax_html, $string, $m, PREG_PATTERN_ORDER );
|
196 |
+
|
197 |
+
if ( isset( $string[0] ) && '{' !== $string[0] && $result && $result >= 1 ) {
|
198 |
+
return true;
|
199 |
+
} else {
|
200 |
+
return false;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
|
205 |
+
/**
|
206 |
+
* @since 2.3.0.2
|
207 |
+
*
|
208 |
+
* Check if there are Weglot menu links and make sure there is the data-wg-notranslate
|
209 |
+
* @param string $content
|
210 |
+
* @return string
|
211 |
+
*/
|
212 |
+
public function fix_menu_link( $content ) {
|
213 |
+
$content = preg_replace( '#<a([^\>]+?)?href="(http|https):\/\/\[weglot_#', '<a$1 data-wg-notranslate="true" href="$2://[weglot_', $content );
|
214 |
+
|
215 |
+
return $content;
|
216 |
+
}
|
217 |
+
|
218 |
+
|
219 |
+
/**
|
220 |
+
* @since 2.3.0
|
221 |
+
*
|
222 |
+
* @param string $html
|
223 |
+
* @return string
|
224 |
+
*/
|
225 |
+
private function remove_comments( $html ) {
|
226 |
+
return preg_replace( '/<!--(.*)-->/Uis', '', $html );
|
227 |
+
}
|
228 |
+
|
229 |
+
|
230 |
+
/**
|
231 |
+
* @since 2.3.0
|
232 |
+
* @param string $dom
|
233 |
+
* @return string
|
234 |
+
*/
|
235 |
+
public function weglot_render_dom( $dom ) {
|
236 |
+
$dom = $this->generate_switcher_service->generate_switcher_from_dom( $dom );
|
237 |
+
|
238 |
+
// We only need this on translated page
|
239 |
+
if ( $this->current_language !== $this->original_language ) {
|
240 |
+
$dom = $this->replace_url_services->replace_link_in_dom( $dom );
|
241 |
+
}
|
242 |
+
|
243 |
+
return apply_filters( 'weglot_render_dom', $dom );
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
|
248 |
+
|
templates/admin/pages/settings.php
CHANGED
@@ -28,6 +28,9 @@ use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
|
|
28 |
case Helper_Tabs_Admin_Weglot::STATUS:
|
29 |
include_once WEGLOT_TEMPLATES_ADMIN_PAGES . '/tabs/status.php';
|
30 |
break;
|
|
|
|
|
|
|
31 |
}
|
32 |
|
33 |
if ( ! in_array( $this->tab_active, [ Helper_Tabs_Admin_Weglot::STATUS ], true ) ) {
|
28 |
case Helper_Tabs_Admin_Weglot::STATUS:
|
29 |
include_once WEGLOT_TEMPLATES_ADMIN_PAGES . '/tabs/status.php';
|
30 |
break;
|
31 |
+
case Helper_Tabs_Admin_Weglot::CUSTOM_URLS:
|
32 |
+
include_once WEGLOT_TEMPLATES_ADMIN_PAGES . '/tabs/custom-urls.php';
|
33 |
+
break;
|
34 |
}
|
35 |
|
36 |
if ( ! in_array( $this->tab_active, [ Helper_Tabs_Admin_Weglot::STATUS ], true ) ) {
|
templates/admin/pages/tabs/advanced.php
CHANGED
@@ -41,6 +41,13 @@ $options_available = [
|
|
41 |
],
|
42 |
];
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
?>
|
45 |
|
46 |
<h3><?php esc_html_e( 'Translation Exclusion (Optional)', 'weglot' ); ?> </h3>
|
@@ -173,12 +180,32 @@ $options_available = [
|
|
173 |
</th>
|
174 |
<td class="forminp forminp-text">
|
175 |
<input
|
176 |
-
name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['private_mode']['key'] ) ); ?>"
|
177 |
id="<?php echo esc_attr( $options_available['private_mode']['key'] ); ?>"
|
|
|
178 |
type="checkbox"
|
179 |
-
<?php checked( $this->options[ $options_available['private_mode']['key'] ], 1 ); ?>
|
180 |
>
|
181 |
<p class="description"><?php echo esc_html( $options_available['private_mode']['description'] ); ?></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
</td>
|
183 |
</tr>
|
184 |
</tbody>
|
@@ -186,10 +213,7 @@ $options_available = [
|
|
186 |
|
187 |
<div class="notice notice-info is-dismissible">
|
188 |
<p>
|
189 |
-
<?php
|
190 |
-
// translators: 1 HTML Tag, 2 HTML Tag
|
191 |
-
echo sprintf( esc_html__( 'If you need any help, you can contact us via email us at support@weglot.com.', 'weglot' ), '<a href="https://weglot.com/" target="_blank">', '</a>' );
|
192 |
-
?>
|
193 |
</p>
|
194 |
<p>
|
195 |
<?php esc_html_e( 'You can also return to version 1.13.1 by clicking on the button below', 'weglot' ); ?>
|
41 |
],
|
42 |
];
|
43 |
|
44 |
+
$languages = weglot_get_languages_configured();
|
45 |
+
foreach ($languages as $key => $value) {
|
46 |
+
if ($value->getIso639() === weglot_get_original_language() ) {
|
47 |
+
unset( $languages[$key] );
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
?>
|
52 |
|
53 |
<h3><?php esc_html_e( 'Translation Exclusion (Optional)', 'weglot' ); ?> </h3>
|
180 |
</th>
|
181 |
<td class="forminp forminp-text">
|
182 |
<input
|
|
|
183 |
id="<?php echo esc_attr( $options_available['private_mode']['key'] ); ?>"
|
184 |
+
name="<?php echo esc_attr( sprintf( '%s[%s][active]', WEGLOT_SLUG, $options_available['private_mode']['key'] ) ); ?>"
|
185 |
type="checkbox"
|
186 |
+
<?php checked( $this->options[ $options_available['private_mode']['key'] ]['active'], 1 ); ?>
|
187 |
>
|
188 |
<p class="description"><?php echo esc_html( $options_available['private_mode']['description'] ); ?></p>
|
189 |
+
<div id="private-mode-detail">
|
190 |
+
<?php foreach ( $languages as $key => $lang):
|
191 |
+
$checked_value = isset( $this->options[ $options_available['private_mode']['key'] ][ $lang->getIso639() ] ) ? $this->options[ $options_available['private_mode']['key'] ][ $lang->getIso639() ] : null;
|
192 |
+
?>
|
193 |
+
<div class="private-mode-detail-lang">
|
194 |
+
<input
|
195 |
+
name="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>"
|
196 |
+
id="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>"
|
197 |
+
type="checkbox"
|
198 |
+
class="private-mode-lang--input"
|
199 |
+
<?php checked( $checked_value, 1 ); ?>
|
200 |
+
/>
|
201 |
+
<label for="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>">
|
202 |
+
<?php
|
203 |
+
// translators: 1 Local name language
|
204 |
+
esc_html_e( sprintf( "Make '%s' a private langauge", $lang->getLocalName() ), 'weglot' ); ?>
|
205 |
+
</label>
|
206 |
+
</div>
|
207 |
+
<?php endforeach; ?>
|
208 |
+
</div>
|
209 |
</td>
|
210 |
</tr>
|
211 |
</tbody>
|
213 |
|
214 |
<div class="notice notice-info is-dismissible">
|
215 |
<p>
|
216 |
+
<?php esc_html_e( 'If you need any help, you can contact us via email us at support@weglot.com.', 'weglot' ); ?>
|
|
|
|
|
|
|
217 |
</p>
|
218 |
<p>
|
219 |
<?php esc_html_e( 'You can also return to version 1.13.1 by clicking on the button below', 'weglot' ); ?>
|
templates/admin/pages/tabs/custom-urls.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
4 |
+
exit;
|
5 |
+
}
|
6 |
+
|
7 |
+
use Weglot\WeglotContext;
|
8 |
+
|
9 |
+
?>
|
10 |
+
|
11 |
+
<h2><?php esc_html_e( 'Custom URLs', 'weglot' ); ?></h2>
|
12 |
+
<?php $options = weglot_get_options(); ?>
|
13 |
+
|
14 |
+
|
15 |
+
<div class="wrap">
|
16 |
+
|
17 |
+
<?php foreach ($options['custom_urls'] as $lang => $urls): ?>
|
18 |
+
|
19 |
+
<h3><?php esc_html_e('Lang : ', 'weglot'); ?><?php echo $lang; ?></h3>
|
20 |
+
|
21 |
+
<div style="display:flex;">
|
22 |
+
<div style="flex:5; margin-right:10px;">
|
23 |
+
<?php esc_html_e('Base URL :', 'weglot'); ?>
|
24 |
+
</div>
|
25 |
+
<div style="flex:5;">
|
26 |
+
<?php esc_html_e('Custom URL :', 'weglot'); ?>
|
27 |
+
</div>
|
28 |
+
<div style="flex:1;"></div>
|
29 |
+
</div>
|
30 |
+
<?php
|
31 |
+
foreach ($urls as $key => $value) {
|
32 |
+
$keyGenerate = sprintf('%s-%s-%s', $lang, $key, $value); ?>
|
33 |
+
<div style="display:flex;" id="<?php echo $keyGenerate; ?>">
|
34 |
+
<div style="margin-right:10px; flex:5;">
|
35 |
+
<input style="max-width:100%;" type="text" value="<?php echo $value ?>" class="base-url base-url-<?php echo $keyGenerate; ?>" data-key="<?php echo $keyGenerate; ?>" name="<?php echo sprintf( '%s[%s][%s][%s]', WEGLOT_SLUG, 'custom_urls', $lang, $key ); ?>" data-lang="<?php echo $lang; ?>" />
|
36 |
+
</div>
|
37 |
+
<div style="flex:5;">
|
38 |
+
<input style="max-width:100%;" type="text" value="<?php echo $key; ?>" data-key="<?php echo $keyGenerate; ?>" class="custom-url custom-<?php echo $keyGenerate; ?>" data-lang="<?php echo $lang; ?>" />
|
39 |
+
</div>
|
40 |
+
|
41 |
+
<div style="align-self:flex-end; flex:1">
|
42 |
+
<button class="js-btn-remove" data-key="<?php echo $keyGenerate; ?>">
|
43 |
+
<span class="dashicons dashicons-minus"></span>
|
44 |
+
</button>
|
45 |
+
</div>
|
46 |
+
|
47 |
+
</div>
|
48 |
+
|
49 |
+
<?php
|
50 |
+
} ?>
|
51 |
+
|
52 |
+
<script>
|
53 |
+
document.addEventListener('DOMContentLoaded', function(){
|
54 |
+
const $ = jQuery
|
55 |
+
|
56 |
+
$('.custom-url').on('keyup', function(e){
|
57 |
+
const key = $(this).data('key')
|
58 |
+
const lang = $(this).data('lang')
|
59 |
+
console.log(key)
|
60 |
+
$('.base-url-' + key).attr('name', 'weglot-translate[custom_urls][' + lang + '][' + e.target.value + ']')
|
61 |
+
})
|
62 |
+
|
63 |
+
$('.js-btn-remove').on('click', function(e){
|
64 |
+
e.preventDefault();
|
65 |
+
|
66 |
+
$('#' + $(this).data('key')).remove()
|
67 |
+
})
|
68 |
+
})
|
69 |
+
</script>
|
70 |
+
|
71 |
+
<?php endforeach; ?>
|
72 |
+
</div>
|
templates/admin/pages/tabs/settings.php
CHANGED
@@ -122,21 +122,21 @@ $plans = $this->user_api_services->get_plans();
|
|
122 |
</select>
|
123 |
|
124 |
<?php
|
125 |
-
if ( $user_info['plan'] <= 0 ) {
|
126 |
?>
|
127 |
<p class="description">
|
128 |
<?php // translators: 1 HTML Tag, 2 HTML Tag ?>
|
129 |
<?php echo sprintf( esc_html__( 'On the free plan, you can choose one language and use a maximum of 2000 words. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
|
130 |
</p>
|
131 |
<?php
|
132 |
-
} elseif ( in_array( $user_info['plan'], $plans['starter_free']['ids'] ) ) { //phpcs:ignore
|
133 |
?>
|
134 |
<p class="description">
|
135 |
<?php // translators: 1 HTML Tag, 2 HTML Tag ?>
|
136 |
<?php echo sprintf( esc_html__( 'On the Starter plan, you can choose one language. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
|
137 |
</p>
|
138 |
<?php
|
139 |
-
} elseif ( in_array( $user_info['plan'], $plans['business']['ids'] ) ) { //phpcs:ignore
|
140 |
?>
|
141 |
<p class="description">
|
142 |
<?php // translators: 1 HTML Tag, 2 HTML Tag ?>
|
122 |
</select>
|
123 |
|
124 |
<?php
|
125 |
+
if ( $user_info && isset( $user_info['plan'] ) && $user_info['plan'] <= 0 ) {
|
126 |
?>
|
127 |
<p class="description">
|
128 |
<?php // translators: 1 HTML Tag, 2 HTML Tag ?>
|
129 |
<?php echo sprintf( esc_html__( 'On the free plan, you can choose one language and use a maximum of 2000 words. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
|
130 |
</p>
|
131 |
<?php
|
132 |
+
} elseif ( isset( $user_info['plan'] ) && in_array( $user_info['plan'], $plans['starter_free']['ids'] ) ) { //phpcs:ignore
|
133 |
?>
|
134 |
<p class="description">
|
135 |
<?php // translators: 1 HTML Tag, 2 HTML Tag ?>
|
136 |
<?php echo sprintf( esc_html__( 'On the Starter plan, you can choose one language. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
|
137 |
</p>
|
138 |
<?php
|
139 |
+
} elseif ( isset( $user_info['plan'] ) && in_array( $user_info['plan'], $plans['business']['ids'] ) ) { //phpcs:ignore
|
140 |
?>
|
141 |
<p class="description">
|
142 |
<?php // translators: 1 HTML Tag, 2 HTML Tag ?>
|
vendor/autoload.php
CHANGED
@@ -4,4 +4,4 @@
|
|
4 |
|
5 |
require_once __DIR__ . '/composer/autoload_real.php';
|
6 |
|
7 |
-
return
|
4 |
|
5 |
require_once __DIR__ . '/composer/autoload_real.php';
|
6 |
|
7 |
+
return ComposerAutoloaderInitdcd4b6e424c9b83714d188a8ae11cec7::getLoader();
|
vendor/composer/autoload_real.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
// autoload_real.php @generated by Composer
|
4 |
|
5 |
-
class
|
6 |
{
|
7 |
private static $loader;
|
8 |
|
@@ -19,15 +19,15 @@ class ComposerAutoloaderInitae38aaded4b3195a3afad33937ac9147
|
|
19 |
return self::$loader;
|
20 |
}
|
21 |
|
22 |
-
spl_autoload_register(array('
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
-
spl_autoload_unregister(array('
|
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\
|
31 |
} else {
|
32 |
$map = require __DIR__ . '/autoload_namespaces.php';
|
33 |
foreach ($map as $namespace => $path) {
|
@@ -48,19 +48,19 @@ class ComposerAutoloaderInitae38aaded4b3195a3afad33937ac9147
|
|
48 |
$loader->register(true);
|
49 |
|
50 |
if ($useStaticLoader) {
|
51 |
-
$includeFiles = Composer\Autoload\
|
52 |
} else {
|
53 |
$includeFiles = require __DIR__ . '/autoload_files.php';
|
54 |
}
|
55 |
foreach ($includeFiles as $fileIdentifier => $file) {
|
56 |
-
|
57 |
}
|
58 |
|
59 |
return $loader;
|
60 |
}
|
61 |
}
|
62 |
|
63 |
-
function
|
64 |
{
|
65 |
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
66 |
require $file;
|
2 |
|
3 |
// autoload_real.php @generated by Composer
|
4 |
|
5 |
+
class ComposerAutoloaderInitdcd4b6e424c9b83714d188a8ae11cec7
|
6 |
{
|
7 |
private static $loader;
|
8 |
|
19 |
return self::$loader;
|
20 |
}
|
21 |
|
22 |
+
spl_autoload_register(array('ComposerAutoloaderInitdcd4b6e424c9b83714d188a8ae11cec7', 'loadClassLoader'), true, true);
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
+
spl_autoload_unregister(array('ComposerAutoloaderInitdcd4b6e424c9b83714d188a8ae11cec7', '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\ComposerStaticInitdcd4b6e424c9b83714d188a8ae11cec7::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\ComposerStaticInitdcd4b6e424c9b83714d188a8ae11cec7::$files;
|
52 |
} else {
|
53 |
$includeFiles = require __DIR__ . '/autoload_files.php';
|
54 |
}
|
55 |
foreach ($includeFiles as $fileIdentifier => $file) {
|
56 |
+
composerRequiredcd4b6e424c9b83714d188a8ae11cec7($fileIdentifier, $file);
|
57 |
}
|
58 |
|
59 |
return $loader;
|
60 |
}
|
61 |
}
|
62 |
|
63 |
+
function composerRequiredcd4b6e424c9b83714d188a8ae11cec7($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
|
8 |
{
|
9 |
public static $files = array (
|
10 |
'6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
|
@@ -45,9 +45,9 @@ class ComposerStaticInitae38aaded4b3195a3afad33937ac9147
|
|
45 |
public static function getInitializer(ClassLoader $loader)
|
46 |
{
|
47 |
return \Closure::bind(function () use ($loader) {
|
48 |
-
$loader->prefixLengthsPsr4 =
|
49 |
-
$loader->prefixDirsPsr4 =
|
50 |
-
$loader->prefixesPsr0 =
|
51 |
|
52 |
}, null, ClassLoader::class);
|
53 |
}
|
4 |
|
5 |
namespace Composer\Autoload;
|
6 |
|
7 |
+
class ComposerStaticInitdcd4b6e424c9b83714d188a8ae11cec7
|
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 = ComposerStaticInitdcd4b6e424c9b83714d188a8ae11cec7::$prefixLengthsPsr4;
|
49 |
+
$loader->prefixDirsPsr4 = ComposerStaticInitdcd4b6e424c9b83714d188a8ae11cec7::$prefixDirsPsr4;
|
50 |
+
$loader->prefixesPsr0 = ComposerStaticInitdcd4b6e424c9b83714d188a8ae11cec7::$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.
|
100 |
-
"version_normalized": "0.5.
|
101 |
"source": {
|
102 |
"type": "git",
|
103 |
"url": "https://github.com/weglot/weglot-php.git",
|
104 |
-
"reference": "
|
105 |
},
|
106 |
"dist": {
|
107 |
"type": "zip",
|
108 |
-
"url": "https://api.github.com/repos/weglot/weglot-php/zipball/
|
109 |
-
"reference": "
|
110 |
"shasum": ""
|
111 |
},
|
112 |
"require": {
|
@@ -118,7 +118,7 @@
|
|
118 |
"codeception/codeception": "^2.4",
|
119 |
"vlucas/phpdotenv": "^2.4"
|
120 |
},
|
121 |
-
"time": "2018-
|
122 |
"type": "library",
|
123 |
"installation-source": "dist",
|
124 |
"autoload": {
|
96 |
},
|
97 |
{
|
98 |
"name": "weglot/weglot-php",
|
99 |
+
"version": "0.5.15",
|
100 |
+
"version_normalized": "0.5.15.0",
|
101 |
"source": {
|
102 |
"type": "git",
|
103 |
"url": "https://github.com/weglot/weglot-php.git",
|
104 |
+
"reference": "291cd6cba7290df7e6e92cd429c7b00bfcc7136d"
|
105 |
},
|
106 |
"dist": {
|
107 |
"type": "zip",
|
108 |
+
"url": "https://api.github.com/repos/weglot/weglot-php/zipball/291cd6cba7290df7e6e92cd429c7b00bfcc7136d",
|
109 |
+
"reference": "291cd6cba7290df7e6e92cd429c7b00bfcc7136d",
|
110 |
"shasum": ""
|
111 |
},
|
112 |
"require": {
|
118 |
"codeception/codeception": "^2.4",
|
119 |
"vlucas/phpdotenv": "^2.4"
|
120 |
},
|
121 |
+
"time": "2018-12-03T16:31:42+00:00",
|
122 |
"type": "library",
|
123 |
"installation-source": "dist",
|
124 |
"autoload": {
|
vendor/weglot/weglot-php/src/Parser/Check/Dom/Placeholder.php
CHANGED
@@ -14,7 +14,7 @@ class Placeholder extends AbstractDomChecker
|
|
14 |
/**
|
15 |
* {@inheritdoc}
|
16 |
*/
|
17 |
-
const DOM = 'input[type="text"],input[type="password"],input[type="search"],input[type="email"],textarea';
|
18 |
|
19 |
/**
|
20 |
* {@inheritdoc}
|
14 |
/**
|
15 |
* {@inheritdoc}
|
16 |
*/
|
17 |
+
const DOM = 'input[type="text"],input[type="password"],input[type="search"],input[type="email"],textarea, input[type="tel"], input[type="number"]';
|
18 |
|
19 |
/**
|
20 |
* {@inheritdoc}
|
vendor/weglot/weglot-php/src/Parser/Formatter/IgnoredNodes.php
CHANGED
@@ -34,11 +34,25 @@ class IgnoredNodes
|
|
34 |
* IgnoredNodes constructor.
|
35 |
* @param string $source
|
36 |
*/
|
37 |
-
public function __construct($source)
|
38 |
{
|
39 |
-
$this
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
43 |
|
44 |
/**
|
34 |
* IgnoredNodes constructor.
|
35 |
* @param string $source
|
36 |
*/
|
37 |
+
public function __construct($source = null)
|
38 |
{
|
39 |
+
$this->setSource($source);
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @param array $ignoredNodes
|
44 |
+
* @return $this
|
45 |
+
*/
|
46 |
+
public function setIgnoredNodes($ignoredNodes){
|
47 |
+
$this->ignoredNodes = $ignoredNodes;
|
48 |
+
return $this;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @return array
|
53 |
+
*/
|
54 |
+
public function getIgnoredNodes(){
|
55 |
+
return $this->ignoredNodes;
|
56 |
}
|
57 |
|
58 |
/**
|
vendor/weglot/weglot-php/src/Parser/Parser.php
CHANGED
@@ -68,6 +68,11 @@ class Parser
|
|
68 |
*/
|
69 |
protected $domCheckerProvider;
|
70 |
|
|
|
|
|
|
|
|
|
|
|
71 |
/**
|
72 |
* Parser constructor.
|
73 |
* @param Client $client
|
@@ -81,7 +86,8 @@ class Parser
|
|
81 |
->setConfigProvider($config)
|
82 |
->setExcludeBlocks($excludeBlocks)
|
83 |
->setWords(new WordCollection())
|
84 |
-
->setDomCheckerProvider(new DomCheckerProvider($this))
|
|
|
85 |
}
|
86 |
|
87 |
/**
|
@@ -216,6 +222,23 @@ class Parser
|
|
216 |
return $this->domCheckerProvider;
|
217 |
}
|
218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
/**
|
220 |
* @param string $source
|
221 |
* @param string $languageFrom
|
@@ -235,7 +258,11 @@ class Parser
|
|
235 |
->setLanguageTo($languageTo);
|
236 |
|
237 |
if ($this->client->getProfile()->getIgnoredNodes()) {
|
238 |
-
$ignoredNodesFormatter =
|
|
|
|
|
|
|
|
|
239 |
$source = $ignoredNodesFormatter->getSource();
|
240 |
}
|
241 |
|
68 |
*/
|
69 |
protected $domCheckerProvider;
|
70 |
|
71 |
+
/**
|
72 |
+
* @var IgnoredNodes
|
73 |
+
*/
|
74 |
+
protected $ignoredNodesFormatter;
|
75 |
+
|
76 |
/**
|
77 |
* Parser constructor.
|
78 |
* @param Client $client
|
86 |
->setConfigProvider($config)
|
87 |
->setExcludeBlocks($excludeBlocks)
|
88 |
->setWords(new WordCollection())
|
89 |
+
->setDomCheckerProvider(new DomCheckerProvider($this))
|
90 |
+
->setIgnoredNodesFormatter(new IgnoredNodes());
|
91 |
}
|
92 |
|
93 |
/**
|
222 |
return $this->domCheckerProvider;
|
223 |
}
|
224 |
|
225 |
+
/**
|
226 |
+
* @param IgnoredNodes $ignoredNodes
|
227 |
+
* @return $this
|
228 |
+
*/
|
229 |
+
public function setIgnoredNodesFormatter(IgnoredNodes $ignoredNodesFormatter)
|
230 |
+
{
|
231 |
+
$this->ignoredNodesFormatter = $ignoredNodesFormatter;
|
232 |
+
return $this;
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* @return IgnoredNodes
|
237 |
+
*/
|
238 |
+
public function getIgnoredNodesFormatter(){
|
239 |
+
return $this->ignoredNodesFormatter;
|
240 |
+
}
|
241 |
+
|
242 |
/**
|
243 |
* @param string $source
|
244 |
* @param string $languageFrom
|
258 |
->setLanguageTo($languageTo);
|
259 |
|
260 |
if ($this->client->getProfile()->getIgnoredNodes()) {
|
261 |
+
$ignoredNodesFormatter = $this->getIgnoredNodesFormatter();
|
262 |
+
|
263 |
+
$ignoredNodesFormatter->setSource($source)
|
264 |
+
->handle();
|
265 |
+
|
266 |
$source = $ignoredNodesFormatter->getSource();
|
267 |
}
|
268 |
|
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/CachedTranslateTest.php
CHANGED
@@ -111,12 +111,12 @@ class CachedTranslateTest extends \Codeception\Test\Unit
|
|
111 |
$this->assertEquals('/translate', $this->translate->getPath());
|
112 |
}
|
113 |
|
114 |
-
public function testCachedRequest()
|
115 |
-
{
|
116 |
-
$translated = $this->translate->handle();
|
117 |
-
$this->assertEquals($this->entry->getInputWords()->count(), $translated->getOutputWords()->count());
|
118 |
-
|
119 |
-
$translated = $this->translate->handle();
|
120 |
-
$this->assertEquals($this->entry->getInputWords()->count(), $translated->getOutputWords()->count());
|
121 |
-
}
|
122 |
}
|
111 |
$this->assertEquals('/translate', $this->translate->getPath());
|
112 |
}
|
113 |
|
114 |
+
// public function testCachedRequest()
|
115 |
+
// {
|
116 |
+
// $translated = $this->translate->handle();
|
117 |
+
// $this->assertEquals($this->entry->getInputWords()->count(), $translated->getOutputWords()->count());
|
118 |
+
|
119 |
+
// $translated = $this->translate->handle();
|
120 |
+
// $this->assertEquals($this->entry->getInputWords()->count(), $translated->getOutputWords()->count());
|
121 |
+
// }
|
122 |
}
|
weglot-functions.php
CHANGED
@@ -62,6 +62,17 @@ function weglot_get_destination_languages() {
|
|
62 |
return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_destination_languages();
|
63 |
}
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
/**
|
66 |
* Get Request Url Service
|
67 |
* @since 2.0
|
@@ -212,3 +223,12 @@ function weglot_get_postid_from_url() {
|
|
212 |
function weglot_get_destination_language() {
|
213 |
return weglot_get_option( 'destination_language' );
|
214 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_destination_languages();
|
63 |
}
|
64 |
|
65 |
+
/**
|
66 |
+
* @since 2.3.0
|
67 |
+
* @return array
|
68 |
+
*/
|
69 |
+
function weglot_get_all_languages_configured() {
|
70 |
+
$destinations = weglot_get_destination_language();
|
71 |
+
$original = weglot_get_original_language();
|
72 |
+
array_unshift( $destinations, $original );
|
73 |
+
return $destinations;
|
74 |
+
}
|
75 |
+
|
76 |
/**
|
77 |
* Get Request Url Service
|
78 |
* @since 2.0
|
223 |
function weglot_get_destination_language() {
|
224 |
return weglot_get_option( 'destination_language' );
|
225 |
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* @since 2.3.0
|
229 |
+
*
|
230 |
+
* @return string
|
231 |
+
*/
|
232 |
+
function weglot_get_private_languages() {
|
233 |
+
return weglot_get_option( 'private_mode' );
|
234 |
+
}
|
weglot.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* @version 2.
|
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.
|
15 |
*/
|
16 |
|
17 |
/**
|
@@ -23,16 +23,16 @@ if ( ! defined('ABSPATH')) {
|
|
23 |
exit;
|
24 |
}
|
25 |
|
26 |
-
|
27 |
define('WEGLOT_NAME', 'Weglot');
|
28 |
define('WEGLOT_SLUG', 'weglot-translate');
|
29 |
define('WEGLOT_OPTION_GROUP', 'group-weglot-translate');
|
30 |
-
define('WEGLOT_VERSION', '2.
|
31 |
define('WEGLOT_PHP_MIN', '5.4');
|
32 |
define('WEGLOT_BNAME', plugin_basename(__FILE__));
|
33 |
define('WEGLOT_DIR', __DIR__ );
|
34 |
define('WEGLOT_DIR_LANGUAGES', WEGLOT_DIR . '/languages');
|
35 |
define('WEGLOT_DIR_DIST', WEGLOT_DIR . '/dist');
|
|
|
36 |
|
37 |
define('WEGLOT_DIRURL', plugin_dir_url(__FILE__));
|
38 |
define('WEGLOT_URL_DIST', WEGLOT_DIRURL . 'dist');
|
1 |
<?php
|
2 |
/**
|
3 |
+
* @version 2.3.0
|
4 |
*/
|
5 |
|
6 |
/*
|
11 |
Author URI: https://weglot.com/
|
12 |
Text Domain: weglot
|
13 |
Domain Path: /languages/
|
14 |
+
Version: 2.3.0
|
15 |
*/
|
16 |
|
17 |
/**
|
23 |
exit;
|
24 |
}
|
25 |
|
|
|
26 |
define('WEGLOT_NAME', 'Weglot');
|
27 |
define('WEGLOT_SLUG', 'weglot-translate');
|
28 |
define('WEGLOT_OPTION_GROUP', 'group-weglot-translate');
|
29 |
+
define('WEGLOT_VERSION', '2.3.0');
|
30 |
define('WEGLOT_PHP_MIN', '5.4');
|
31 |
define('WEGLOT_BNAME', plugin_basename(__FILE__));
|
32 |
define('WEGLOT_DIR', __DIR__ );
|
33 |
define('WEGLOT_DIR_LANGUAGES', WEGLOT_DIR . '/languages');
|
34 |
define('WEGLOT_DIR_DIST', WEGLOT_DIR . '/dist');
|
35 |
+
define('WEGLOT_DEBUG', false);
|
36 |
|
37 |
define('WEGLOT_DIRURL', plugin_dir_url(__FILE__));
|
38 |
define('WEGLOT_URL_DIST', WEGLOT_DIRURL . 'dist');
|