Weglot Translate – Translate your WP website - Version 3.1.8

Version Description

(02/07/2020) = * Exclude URL by languages * Translate by default all Woocommerce mails with customer language * Update URLs translation, possibility to use custom URLs for hierarchical pages * Translate External URLs * Add SVG files to media translation * Exclude wp-cron.php from translation * Fix links translation with custom URLS

Download this release

Release Info

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

Code changes from version 3.1.7 to 3.1.8

Files changed (126) hide show
  1. app/javascripts/settings/admin-exclusion.js +0 -19
  2. bootstrap.php +101 -100
  3. dist/admin-js.js +1 -1
  4. readme.txt +10 -1
  5. src/actions/admin/class-admin-enqueue-weglot.php +16 -16
  6. src/actions/admin/class-ajax-user-info.php +1 -1
  7. src/actions/admin/class-customize-menu-weglot.php +15 -15
  8. src/actions/admin/class-metabox-url-translate-weglot.php +83 -60
  9. src/actions/admin/class-options-weglot.php +32 -48
  10. src/actions/admin/class-pages-weglot.php +3 -4
  11. src/actions/admin/class-plugin-links-weglot.php +2 -2
  12. src/actions/class-email-translate-weglot.php +3 -4
  13. src/actions/class-migration-weglot.php +4 -2
  14. src/actions/class-register-widget-weglot.php +4 -2
  15. src/actions/front/class-clean-options.php +3 -3
  16. src/actions/front/class-front-enqueue-weglot.php +3 -3
  17. src/actions/front/class-front-menu-weglot.php +28 -28
  18. src/actions/front/class-redirect-comment.php +1 -1
  19. src/actions/front/class-redirect-log-user-weglot.php +1 -1
  20. src/actions/front/class-search-weglot.php +11 -11
  21. src/actions/front/class-shortcode-weglot.php +1 -1
  22. src/actions/front/class-translate-page-weglot.php +57 -61
  23. src/class-bootstrap-weglot.php +3 -2
  24. src/domcheckers/class-button-data-value.php +4 -3
  25. src/domcheckers/class-button-value.php +4 -3
  26. src/domcheckers/class-input-reset.php +5 -3
  27. src/domcheckers/class-link-data-href.php +3 -2
  28. src/domcheckers/class-meta-facebook-image.php +5 -3
  29. src/domcheckers/class-meta-twitter-image.php +5 -3
  30. src/domcheckers/class-meta-twitter.php +5 -3
  31. src/domcheckers/class-video-source.php +5 -3
  32. src/domlisteners/class-meta-listener-weglot.php +9 -8
  33. src/helpers/class-helper-api.php +4 -5
  34. src/helpers/class-helper-excluded-type.php +3 -2
  35. src/helpers/class-helper-filter-url-weglot.php +10 -9
  36. src/helpers/class-helper-flag-type.php +1 -1
  37. src/helpers/class-helper-is-admin.php +3 -4
  38. src/helpers/class-helper-json-inline-weglot.php +1 -0
  39. src/helpers/class-helper-menu-options-weglot.php +21 -14
  40. src/helpers/class-helper-pages-weglot.php +1 -0
  41. src/helpers/class-helper-post-meta-weglot.php +1 -0
  42. src/helpers/class-helper-replace-url-weglot.php +3 -2
  43. src/helpers/class-helper-rollback-weglot.php +15 -12
  44. src/helpers/class-helper-tabs-admin-weglot.php +12 -11
  45. src/models/class-abstract-notices-weglot.php +1 -0
  46. src/models/class-hooks-interface-weglot.php +1 -0
  47. src/models/class-schema-option-migration-v3.php +26 -25
  48. src/models/class-schema-option-v3.php +34 -33
  49. src/models/class-third-active-interface-weglot.php +1 -0
  50. src/notices/class-curl-weglot.php +1 -0
  51. src/notices/class-json-function-weglot.php +1 -0
  52. src/notices/class-no-configuration-weglot.php +1 -0
  53. src/notices/class-rewrite-module-weglot.php +1 -0
  54. src/services/class-button-service-weglot.php +26 -26
  55. src/services/class-custom-url-service-weglot.php +32 -30
  56. src/services/class-dom-checkers-service-weglot.php +12 -8
  57. src/services/class-dom-listeners-service-weglot.php +2 -2
  58. src/services/class-email-translate-service-weglot.php +12 -12
  59. src/services/class-generate-switcher-service-weglot.php +13 -12
  60. src/services/class-href-lang-service-weglot.php +6 -5
  61. src/services/class-language-service-weglot.php +46 -16
  62. src/services/class-menu-options-service-weglot.php +10 -4
  63. src/services/class-migration-service-weglot.php +1 -1
  64. src/services/class-multisite-service-weglot.php +7 -5
  65. src/services/class-option-service-weglot.php +243 -119
  66. src/services/class-parser-service-weglot.php +25 -20
  67. src/services/class-private-language-service-weglot.php +5 -5
  68. src/services/class-redirect-service-weglot.php +16 -16
  69. src/services/class-regex-checkers-service-weglot.php +39 -39
  70. src/services/class-replace-link-service-weglot.php +69 -53
  71. src/services/class-replace-url-service-weglot.php +10 -8
  72. src/services/class-request-url-service-weglot.php +23 -21
  73. src/services/class-translate-service-weglot.php +5 -6
  74. src/services/class-user-api-service-weglot.php +26 -25
  75. src/third/amp/class-amp-enqueue-weglot.php +3 -2
  76. src/third/cacheenabler/class-cache-enabler-active.php +1 -2
  77. src/third/cacheenabler/class-cache-enabler-cache.php +4 -3
  78. src/third/calderaforms/class-caldera-active.php +1 -3
  79. src/third/calderaforms/class-caldera-i18n-inline.php +1 -2
  80. src/third/calderaforms/regexcheckers/class-caldera-form-json-fields.php +10 -10
  81. src/third/contactform7/class-contactform7-active.php +1 -2
  82. src/third/contactform7/class-contactform7-json-keys.php +2 -1
  83. src/third/edd/class-edd-active.php +1 -3
  84. src/third/edd/class-edd-filter-urls.php +5 -4
  85. src/third/gravityforms/class-gf-active.php +1 -3
  86. src/third/gravityforms/class-gf-filter-urls.php +6 -5
  87. src/third/mailoptin/class-mailoptin-active.php +1 -3
  88. src/third/mailoptin/regexcheckers/class-mailoptin-json.php +10 -10
  89. src/third/maintenance/class-maintenance-active.php +1 -2
  90. src/third/maintenance/class-maintenance-tracking.php +6 -5
  91. src/third/ninjaforms/class-ninja-active.php +1 -3
  92. src/third/ninjaforms/regexcheckers/class-ninja-form-json-fields.php +10 -10
  93. src/third/ninjaforms/regexcheckers/class-ninja-form-json-nfi18n.php +10 -10
  94. src/third/ninjaforms/regexcheckers/class-ninja-form-json-setting.php +10 -10
  95. src/third/theeventscalendar/class-theeventscalendar-active.php +1 -2
  96. src/third/theeventscalendar/class-theeventscalendar-words.php +2 -1
  97. src/third/underconstructionpage/class-ucp-active.php +1 -2
  98. src/third/underconstructionpage/class-ucp-tracking.php +6 -5
  99. src/third/woocommerce/class-wc-active.php +1 -3
  100. src/third/woocommerce/class-wc-cart-reload-weglot.php +9 -8
  101. src/third/woocommerce/class-wc-filter-urls-weglot.php +41 -41
  102. src/third/woocommerce/class-wc-mail-weglot.php +4 -4
  103. src/third/woocommerce/regexcheckers/class-wc-json-add-cart.php +10 -10
  104. src/third/woocommerce/regexcheckers/class-wc-json-address.php +10 -10
  105. src/third/wpforms/class-wpforms-active.php +1 -3
  106. src/third/wpforms/regexcheckers/class-wp-form-json-setting.php +10 -9
  107. src/third/wpoptimize/class-wp-optimize-active.php +1 -2
  108. src/third/wpoptimize/class-wp-optimize-cache.php +1 -0
  109. src/third/yoast/class-redirect-handler-weglot.php +3 -2
  110. src/widgets/class-widget-selector-weglot.php +8 -6
  111. templates/admin/metaboxes/url-translate.php +26 -13
  112. templates/admin/notices/no-configuration.php +1 -0
  113. templates/admin/pages/tabs/advanced.php +5 -44
  114. vendor/autoload.php +1 -1
  115. vendor/composer/autoload_real.php +7 -7
  116. vendor/composer/autoload_static.php +5 -5
  117. vendor/composer/installed.json +12 -12
  118. vendor/weglot/translation-definitions/data/cases/cases-v3.json +10 -0
  119. vendor/weglot/weglot-php/CHANGELOG.md +10 -0
  120. vendor/weglot/weglot-php/src/Client/Api/Enum/WordType.php +2 -1
  121. vendor/weglot/weglot-php/src/Parser/Check/Dom/ExternalLinkHref.php +49 -0
  122. vendor/weglot/weglot-php/src/Parser/Check/DomCheckerProvider.php +1 -0
  123. vendor/weglot/weglot-php/src/Parser/Check/RegexCheckerProvider.php +2 -2
  124. weglot-compatibility.php +2 -1
  125. weglot-functions.php +20 -1
  126. weglot.php +2 -2
app/javascripts/settings/admin-exclusion.js CHANGED
@@ -3,7 +3,6 @@ const init_admin_exclusion = function () {
3
  const execute = () => {
4
  const template_add_exclude_url = document.querySelector("#tpl-exclusion-url");
5
  const template_add_exclude_block = document.querySelector("#tpl-exclusion-block");
6
- const parent_exclude_url_append = document.querySelector("#container-exclude_urls");
7
  const parent_exclude_block_append = document.querySelector("#container-exclude_blocks");
8
 
9
  function removeLine(e) {
@@ -11,24 +10,6 @@ const init_admin_exclusion = function () {
11
  this.parentNode.remove()
12
  }
13
 
14
- if (document.querySelector("#js-add-exclude-url")) {
15
-
16
- document
17
- .querySelector("#js-add-exclude-url")
18
- .addEventListener("click", (e) => {
19
- e.preventDefault()
20
- const random_key = Math.random().toString(36).substring(7);
21
- parent_exclude_url_append.insertAdjacentHTML("beforeend", template_add_exclude_url.innerHTML.replace(new RegExp('{KEY}', 'g'), random_key));
22
- document
23
- .querySelector(
24
- "#container-exclude_urls .item-exclude:last-child .js-btn-remove"
25
- )
26
- .addEventListener("click", removeLine);
27
- });
28
-
29
- }
30
-
31
-
32
  if (document.querySelector("#js-add-exclude-block")) {
33
  document
34
  .querySelector("#js-add-exclude-block")
3
  const execute = () => {
4
  const template_add_exclude_url = document.querySelector("#tpl-exclusion-url");
5
  const template_add_exclude_block = document.querySelector("#tpl-exclusion-block");
 
6
  const parent_exclude_block_append = document.querySelector("#container-exclude_blocks");
7
 
8
  function removeLine(e) {
10
  this.parentNode.remove()
11
  }
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  if (document.querySelector("#js-add-exclude-block")) {
14
  document
15
  .querySelector("#js-add-exclude-block")
bootstrap.php CHANGED
@@ -1,11 +1,12 @@
1
  <?php // phpcs:ignore
2
 
3
  if ( ! defined( 'ABSPATH' ) ) {
4
- exit;
5
  }
6
 
7
  use WeglotWP\Bootstrap_Weglot;
8
 
 
9
  /**
10
  * Only use for get one context
11
  *
@@ -13,57 +14,57 @@ use WeglotWP\Bootstrap_Weglot;
13
  */
14
  abstract class Context_Weglot {
15
 
16
- /**
17
- * @static
18
- * @since 2.0
19
- * @var Bootstrap_Weglot|null
20
- */
21
- protected static $context;
22
-
23
- /**
24
- * Create context if not exist
25
- *
26
- * @static
27
- * @since 2.0
28
- * @return void
29
- */
30
- public static function weglot_get_context() {
31
- if ( null !== self::$context ) {
32
- return self::$context;
33
- }
34
-
35
- self::$context = new Bootstrap_Weglot();
36
-
37
- // If PHP > 5.6, it will be possible to autoload the classes without listing them
38
- $services = [
39
- '\WeglotWP\Services\Button_Service_Weglot',
40
- '\WeglotWP\Services\Request_Url_Service_Weglot',
41
- '\WeglotWP\Services\Option_Service_Weglot',
42
- '\WeglotWP\Services\Redirect_Service_Weglot',
43
- '\WeglotWP\Services\Language_Service_Weglot',
44
- '\WeglotWP\Services\Replace_Url_Service_Weglot',
45
- '\WeglotWP\Services\Multisite_Service_Weglot',
46
- '\WeglotWP\Services\Replace_Link_Service_Weglot',
47
- '\WeglotWP\Services\Migration_Service_Weglot',
48
- '\WeglotWP\Services\Dom_Listeners_Service_Weglot',
49
- '\WeglotWP\Services\Parser_Service_Weglot',
50
- '\WeglotWP\Services\User_Api_Service_Weglot',
51
- '\WeglotWP\Services\Dom_Checkers_Service_Weglot',
52
- '\WeglotWP\Services\Regex_Checkers_Service_Weglot',
53
- '\WeglotWP\Services\Custom_Url_Service_Weglot',
54
- '\WeglotWP\Services\Generate_Switcher_Service_Weglot',
55
- '\WeglotWP\Services\Email_Translate_Service_Weglot',
56
- '\WeglotWP\Services\Translate_Service_Weglot',
57
- '\WeglotWP\Services\Private_Language_Service_Weglot',
58
- '\WeglotWP\Services\Href_Lang_Service_Weglot',
59
- '\WeglotWP\Services\Menu_Options_Service_Weglot',
60
-
61
- '\WeglotWP\Third\Amp\Amp_Service_Weglot',
62
- '\WeglotWP\Third\Calderaforms\Caldera_Active',
63
- '\WeglotWP\Third\Edd\Edd_Active',
64
- '\WeglotWP\Third\Gravityforms\Gf_Active',
65
- '\WeglotWP\Third\NinjaForms\Ninja_Active',
66
- '\WeglotWP\Third\Woocommerce\Wc_Active',
67
  '\WeglotWP\Third\WPForms\Wpforms_Active',
68
  '\WeglotWP\Third\UnderConstructionPage\Ucp_Active',
69
  '\WeglotWP\Third\Maintenance\Maintenance_Active',
@@ -72,51 +73,51 @@ abstract class Context_Weglot {
72
  '\WeglotWP\Third\ContactForm7\Contactform7_Active',
73
  '\WeglotWP\Third\WpOptimize\Wp_Optimize_Active',
74
  '\WeglotWP\Third\CacheEnabler\Cache_Enabler_Active',
75
- ];
76
-
77
- self::$context->set_services( $services );
78
-
79
- // If PHP > 5.6, it will be possible to autoload the classes without listing them
80
- $actions = [
81
- '\WeglotWP\Actions\Email_Translate_Weglot',
82
- '\WeglotWP\Actions\Register_Widget_Weglot',
83
- '\WeglotWP\Actions\Admin\Pages_Weglot',
84
- '\WeglotWP\Actions\Admin\Plugin_Links_Weglot',
85
- '\WeglotWP\Actions\Admin\Options_Weglot',
86
- '\WeglotWP\Actions\Admin\Admin_Enqueue_Weglot',
87
- '\WeglotWP\Actions\Admin\Customize_Menu_Weglot',
88
- '\WeglotWP\Actions\Admin\Permalink_Weglot',
89
- '\WeglotWP\Actions\Front\Translate_Page_Weglot',
90
- '\WeglotWP\Actions\Front\Front_Enqueue_Weglot',
91
- '\WeglotWP\Actions\Front\Shortcode_Weglot',
92
- '\WeglotWP\Actions\Front\Redirect_Log_User_Weglot',
93
- '\WeglotWP\Actions\Migration_Weglot',
94
- '\WeglotWP\Actions\Admin\Metabox_Url_Translate_Weglot',
95
- '\WeglotWP\Actions\Front\Front_Menu_Weglot',
96
- '\WeglotWP\Actions\Front\Search_Weglot',
97
- '\WeglotWP\Actions\Front\Redirect_Comment',
98
- '\WeglotWP\Actions\Admin\Ajax_User_Info',
99
- '\WeglotWP\Actions\Front\Clean_Options',
100
-
101
- '\WeglotWP\Third\Amp\Amp_Enqueue_Weglot',
102
- '\WeglotWP\Third\Calderaforms\Caldera_I18n_Inline',
103
- '\WeglotWP\Third\Edd\Edd_Filter_Urls',
104
- '\WeglotWP\Third\Gravityforms\GF_Filter_Urls',
105
- '\WeglotWP\Third\Woocommerce\WC_Filter_Urls_Weglot',
106
- '\WeglotWP\Third\Woocommerce\WC_Cart_Reload_Weglot',
107
- '\WeglotWP\Third\Woocommerce\WC_Mail_Weglot',
108
  '\WeglotWP\Third\UnderConstructionPage\Ucp_Tracking',
109
  '\WeglotWP\Third\Maintenance\Maintenance_Tracking',
110
  '\WeglotWP\Third\TheEventsCalendar\Theeventscalendar_Words',
111
- '\WeglotWP\Third\Contactform7\Contactform7_Json_Keys',
112
  '\WeglotWP\Third\WpOptimize\Wp_Optimize_Cache',
113
  '\WeglotWP\Third\CacheEnabler\Cache_Enabler_Cache',
114
- ];
115
 
116
  self::$context->set_actions( $actions );
117
 
118
- return self::$context;
119
- }
120
  }
121
 
122
 
@@ -127,19 +128,19 @@ abstract class Context_Weglot {
127
  * @return void
128
  */
129
  function weglot_init() {
130
- if ( function_exists( 'apache_get_modules' ) && ! in_array( 'mod_rewrite', apache_get_modules() ) ) { //phpcs:ignore
131
- add_action( 'admin_notices', [ '\WeglotWP\Notices\Rewrite_Module_Weglot', 'admin_notice' ] );
132
- }
133
 
134
- if ( ! function_exists( 'curl_version' ) ) {
135
- add_action( 'admin_notices', [ '\WeglotWP\Notices\Curl_Weglot', 'admin_notice' ] );
136
- }
137
 
138
- if ( ! function_exists( 'json_last_error' ) ) {
139
- add_action( 'admin_notices', [ '\WeglotWP\Notices\Json_Function_Weglot', 'admin_notice' ] );
140
- }
141
 
142
- load_plugin_textdomain( 'weglot', false, WEGLOT_DIR_LANGUAGES );
143
 
144
- Context_Weglot::weglot_get_context()->init_plugin();
145
  }
1
  <?php // phpcs:ignore
2
 
3
  if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
  }
6
 
7
  use WeglotWP\Bootstrap_Weglot;
8
 
9
+
10
  /**
11
  * Only use for get one context
12
  *
14
  */
15
  abstract class Context_Weglot {
16
 
17
+ /**
18
+ * @static
19
+ * @since 2.0
20
+ * @var Bootstrap_Weglot|null
21
+ */
22
+ protected static $context;
23
+
24
+ /**
25
+ * Create context if not exist
26
+ *
27
+ * @static
28
+ * @since 2.0
29
+ * @return void
30
+ */
31
+ public static function weglot_get_context() {
32
+ if ( null !== self::$context ) {
33
+ return self::$context;
34
+ }
35
+
36
+ self::$context = new Bootstrap_Weglot();
37
+
38
+ // If PHP > 5.6, it will be possible to autoload the classes without listing them
39
+ $services = array(
40
+ '\WeglotWP\Services\Button_Service_Weglot',
41
+ '\WeglotWP\Services\Request_Url_Service_Weglot',
42
+ '\WeglotWP\Services\Option_Service_Weglot',
43
+ '\WeglotWP\Services\Redirect_Service_Weglot',
44
+ '\WeglotWP\Services\Language_Service_Weglot',
45
+ '\WeglotWP\Services\Replace_Url_Service_Weglot',
46
+ '\WeglotWP\Services\Multisite_Service_Weglot',
47
+ '\WeglotWP\Services\Replace_Link_Service_Weglot',
48
+ '\WeglotWP\Services\Migration_Service_Weglot',
49
+ '\WeglotWP\Services\Dom_Listeners_Service_Weglot',
50
+ '\WeglotWP\Services\Parser_Service_Weglot',
51
+ '\WeglotWP\Services\User_Api_Service_Weglot',
52
+ '\WeglotWP\Services\Dom_Checkers_Service_Weglot',
53
+ '\WeglotWP\Services\Regex_Checkers_Service_Weglot',
54
+ '\WeglotWP\Services\Custom_Url_Service_Weglot',
55
+ '\WeglotWP\Services\Generate_Switcher_Service_Weglot',
56
+ '\WeglotWP\Services\Email_Translate_Service_Weglot',
57
+ '\WeglotWP\Services\Translate_Service_Weglot',
58
+ '\WeglotWP\Services\Private_Language_Service_Weglot',
59
+ '\WeglotWP\Services\Href_Lang_Service_Weglot',
60
+ '\WeglotWP\Services\Menu_Options_Service_Weglot',
61
+
62
+ '\WeglotWP\Third\Amp\Amp_Service_Weglot',
63
+ '\WeglotWP\Third\Calderaforms\Caldera_Active',
64
+ '\WeglotWP\Third\Edd\Edd_Active',
65
+ '\WeglotWP\Third\Gravityforms\Gf_Active',
66
+ '\WeglotWP\Third\NinjaForms\Ninja_Active',
67
+ '\WeglotWP\Third\Woocommerce\Wc_Active',
68
  '\WeglotWP\Third\WPForms\Wpforms_Active',
69
  '\WeglotWP\Third\UnderConstructionPage\Ucp_Active',
70
  '\WeglotWP\Third\Maintenance\Maintenance_Active',
73
  '\WeglotWP\Third\ContactForm7\Contactform7_Active',
74
  '\WeglotWP\Third\WpOptimize\Wp_Optimize_Active',
75
  '\WeglotWP\Third\CacheEnabler\Cache_Enabler_Active',
76
+ );
77
+
78
+ self::$context->set_services( $services );
79
+
80
+ // If PHP > 5.6, it will be possible to autoload the classes without listing them
81
+ $actions = array(
82
+ '\WeglotWP\Actions\Email_Translate_Weglot',
83
+ '\WeglotWP\Actions\Register_Widget_Weglot',
84
+ '\WeglotWP\Actions\Admin\Pages_Weglot',
85
+ '\WeglotWP\Actions\Admin\Plugin_Links_Weglot',
86
+ '\WeglotWP\Actions\Admin\Options_Weglot',
87
+ '\WeglotWP\Actions\Admin\Admin_Enqueue_Weglot',
88
+ '\WeglotWP\Actions\Admin\Customize_Menu_Weglot',
89
+ '\WeglotWP\Actions\Admin\Permalink_Weglot',
90
+ '\WeglotWP\Actions\Front\Translate_Page_Weglot',
91
+ '\WeglotWP\Actions\Front\Front_Enqueue_Weglot',
92
+ '\WeglotWP\Actions\Front\Shortcode_Weglot',
93
+ '\WeglotWP\Actions\Front\Redirect_Log_User_Weglot',
94
+ '\WeglotWP\Actions\Migration_Weglot',
95
+ '\WeglotWP\Actions\Admin\Metabox_Url_Translate_Weglot',
96
+ '\WeglotWP\Actions\Front\Front_Menu_Weglot',
97
+ '\WeglotWP\Actions\Front\Search_Weglot',
98
+ '\WeglotWP\Actions\Front\Redirect_Comment',
99
+ '\WeglotWP\Actions\Admin\Ajax_User_Info',
100
+ '\WeglotWP\Actions\Front\Clean_Options',
101
+
102
+ '\WeglotWP\Third\Amp\Amp_Enqueue_Weglot',
103
+ '\WeglotWP\Third\Calderaforms\Caldera_I18n_Inline',
104
+ '\WeglotWP\Third\Edd\Edd_Filter_Urls',
105
+ '\WeglotWP\Third\Gravityforms\GF_Filter_Urls',
106
+ '\WeglotWP\Third\Woocommerce\WC_Filter_Urls_Weglot',
107
+ '\WeglotWP\Third\Woocommerce\WC_Cart_Reload_Weglot',
108
+ '\WeglotWP\Third\Woocommerce\WC_Mail_Weglot',
109
  '\WeglotWP\Third\UnderConstructionPage\Ucp_Tracking',
110
  '\WeglotWP\Third\Maintenance\Maintenance_Tracking',
111
  '\WeglotWP\Third\TheEventsCalendar\Theeventscalendar_Words',
112
+ '\WeglotWP\Third\Contactform7\Contactform7_Json_Keys',
113
  '\WeglotWP\Third\WpOptimize\Wp_Optimize_Cache',
114
  '\WeglotWP\Third\CacheEnabler\Cache_Enabler_Cache',
115
+ );
116
 
117
  self::$context->set_actions( $actions );
118
 
119
+ return self::$context;
120
+ }
121
  }
122
 
123
 
128
  * @return void
129
  */
130
  function weglot_init() {
131
+ if ( function_exists( 'apache_get_modules' ) && ! in_array( 'mod_rewrite', apache_get_modules() ) ) { //phpcs:ignore
132
+ add_action( 'admin_notices', array( '\WeglotWP\Notices\Rewrite_Module_Weglot', 'admin_notice' ) );
133
+ }
134
 
135
+ if ( ! function_exists( 'curl_version' ) ) {
136
+ add_action( 'admin_notices', array( '\WeglotWP\Notices\Curl_Weglot', 'admin_notice' ) );
137
+ }
138
 
139
+ if ( ! function_exists( 'json_last_error' ) ) {
140
+ add_action( 'admin_notices', array( '\WeglotWP\Notices\Json_Function_Weglot', 'admin_notice' ) );
141
+ }
142
 
143
+ load_plugin_textdomain( 'weglot', false, WEGLOT_DIR_LANGUAGES );
144
 
145
+ Context_Weglot::weglot_get_context()->init_plugin();
146
  }
dist/admin-js.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function o(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,o),a.l=!0,a.exports}o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)o.d(n,a,function(t){return e[t]}.bind(null,a));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/dist/",o(o.s=5)}([function(e,t){Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),o=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var n=arguments[1],a=0;a<o;){var l=t[a];if(e.call(n,l,a,t))return l;a++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var o=this.length>>>0,n=new Array(o),a=this,l=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(a[r],r,a)&&(n[l++]=a[r]);else for(;++r!==o;)r in this&&e.call(t,a[r],r,a)&&(n[l++]=a[r]);return n.length=l,n})},,,,function(e,t,o){"use strict";o.r(t);var n=function(){const e=jQuery,t=()=>weglot_languages.available.filter(e=>e.code!==weglot_languages.original);let o;const n=()=>{let n=e("#original_language").val();e("#original_language").on("change",function(t){const a=n,l=n;n=t.target.value,o[0].selectize.removeOption(n);const r=weglot_languages.available.find(e=>e.code===l),s=weglot_languages.available.find(e=>e.code===n);o[0].selectize.addOption(r);const c=e("#is_fullname").is(":checked");let i="";e("#with_name").is(":checked")&&(i=c?s.local:s.code.toUpperCase()),e(".wgcurrent.wg-li").removeClass(a).addClass(n).attr("data-code-language",n).find("span").html(i)}),o=e(".weglot-select-destination").selectize({delimiter:"|",persist:!1,valueField:"code",labelField:"local",searchField:["code","english","local"],sortField:[{field:"english",direction:"asc"}],maxItems:weglot_languages.limit,plugins:["remove_button","drag_drop"],options:t(),render:{option:function(e,t){return'<div class="weglot__choice__language"><span class="weglot__choice__language--english">'+t(e.english)+'</span><span class="weglot__choice__language--local">'+t(e.local)+" ["+t(e.code)+"]</span></div>"}}}).on("change",t=>{const n=o[0].selectize.getValue(),a=e("#li-button-tpl");if(0===a.length)return;const l=e("#is_fullname").is(":checked"),r=e("#with_name").is(":checked"),s=e("#with_flags").is(":checked");let c="";s&&(c="weglot-flags");let i="";n.forEach(e=>{const t=weglot_languages.available.find(t=>t.code===e);let o="";r&&(o=l?t.local:e.toUpperCase()),i+=a.html().replace("{LABEL_LANGUAGE}",o).replace(new RegExp("{CODE_LANGUAGE}","g"),e).replace("{CLASSES}",c)}),e(".country-selector ul").html(i)}),window.addEventListener("weglotCheckApi",e=>{let t=1e3;const n=e.detail.plan;n<=0||weglot_languages.plans.starter_free.ids.indexOf(n)>=0?t=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(n)>=0&&(t=weglot_languages.plans.business.limit_language),o[0].selectize.settings.maxItems=t})};document.addEventListener("DOMContentLoaded",()=>{n()})};var a=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{e("#weglot-box-first-settings .weglot-btn-close").on("click",function(t){t.preventDefault(),e("#weglot-box-first-settings").hide()})})};var l=function(){const e=()=>{const e=document.querySelector("#tpl-exclusion-url"),t=document.querySelector("#tpl-exclusion-block"),o=document.querySelector("#container-exclude_urls"),n=document.querySelector("#container-exclude_blocks");function a(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-url")&&document.querySelector("#js-add-exclude-url").addEventListener("click",t=>{t.preventDefault();const n=Math.random().toString(36).substring(7);o.insertAdjacentHTML("beforeend",e.innerHTML.replace(new RegExp("{KEY}","g"),n)),document.querySelector("#container-exclude_urls .item-exclude:last-child .js-btn-remove").addEventListener("click",a)}),document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",e=>{e.preventDefault(),n.insertAdjacentHTML("beforeend",t.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",a)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",a)})};document.addEventListener("DOMContentLoaded",()=>{e()})};var r=function(){const e=jQuery,t=()=>{let t=e("#type_flags option:selected").data("value"),o=[];o.push(e(".country-selector label").data("code-language")),e(".country-selector li").each((t,n)=>{o.push(e(n).data("code-language"))});const n=weglot_languages.available.filter(e=>o.indexOf(e.code)>=0);e("#weglot-css-inline").text(weglot_css.inline),e("#is_dropdown").on("change",function(){e(".country-selector").toggleClass("weglot-inline"),e(".country-selector").toggleClass("weglot-dropdown")}),e("#with_flags").on("change",function(){e(".country-selector label, .country-selector li").toggleClass("weglot-flags")}),e("#type_flags").on("change",function(o){e(".country-selector label, .country-selector li").removeClass(`flag-${t}`);const n=e(":selected",this).data("value");e(".country-selector label, .country-selector li").addClass(`flag-${n}`),t=n});const a=()=>{const t=n.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),a=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(a),e(".country-selector li").each((t,a)=>{const l=n.find(t=>t.code===e(a).data("code-language")),r=o?l.local:l.code.toUpperCase();e(a).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?a():(e(".country-selector label a, .country-selector label span").text(""),e(".country-selector li a, .country-selector li span").each((t,o)=>{e(o).text("")}))}),e("#is_fullname").on("change",function(t){if(e("#with_name").is(":checked"))if(t.target.checked)a();else{const t=n.find(t=>t.code===e(".country-selector label").data("code-language"));e(".country-selector label a, .country-selector label span").text(t.code.toUpperCase()),e(".country-selector li").each((t,o)=>{const a=n.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(a.code.toUpperCase()),e(o).find("span").text(a.code.toUpperCase())})}}),e("#override_css").on("keyup",function(t){e("#weglot-css-inline").text(t.target.value)})};document.addEventListener("DOMContentLoaded",()=>{0!==e(".weglot-preview").length&&t()})};var s=function(){const e=jQuery,t=()=>{e("#api_key_private").blur(function(){var t=e(this).val();if(0===t.length)return e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>'),void e("#wrap-weglot #submit").prop("disabled",!0);function o(){e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!0)}e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-ckeckkey"></span>'),e.ajax({method:"POST",url:ajaxurl,data:{action:"get_user_info",api_key:t},success:({data:t,success:n})=>{e(".weglot-keyres").remove(),n?function(t){e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-okkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!1);const o=new CustomEvent("weglotCheckApi",{detail:t});window.dispatchEvent(o)}(t):o()}}).fail(function(){o()})})};document.addEventListener("DOMContentLoaded",()=>{t()})};var c=function(){jQuery;document.addEventListener("DOMContentLoaded",()=>{jQuery(document).ready(function(e){wp.codeEditor.initialize(e("#override_css"),cm_settings)})})};var i=function(){const e=jQuery;"undefined"!=typeof weglot_css&&e("#weglot-css-flag-css").text(weglot_css.flag_css);const t=()=>{e(".flag-style-openclose").on("click",function(){e(".flag-style-wrapper").toggle()}),e("select.flag-en-type, select.flag-es-type, select.flag-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; } ",d=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; } ",u=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+d+u+p+w)}()})};document.addEventListener("DOMContentLoaded",()=>{t()})};var g=function(){jQuery;document.addEventListener("DOMContentLoaded",()=>{const e=document.querySelector("#private_mode");e&&0!=e.length&&(document.querySelector("#private_mode").addEventListener("change",function(e){document.querySelectorAll(".private-mode-lang--input").forEach(t=>{t.checked=e.target.checked})}),document.querySelectorAll(".private-mode-lang--input").forEach(e=>{e.addEventListener("change",function(e){0===document.querySelectorAll(".private-mode-lang--input:checked").length&&(document.querySelector("#private_mode").checked=!1)})}))})};o(0),o(1);n(),l(),a(),r(),s(),c(),i(),g()}]);
1
+ !function(e){var t={};function o(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,o),n.l=!0,n.exports}o.m=e,o.c=t,o.d=function(e,t,a){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(o.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(a,n,function(t){return e[t]}.bind(null,n));return a},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/dist/",o(o.s=5)}([function(e,t){Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),o=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var a=arguments[1],n=0;n<o;){var l=t[n];if(e.call(a,l,n,t))return l;n++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var o=this.length>>>0,a=new Array(o),n=this,l=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(n[r],r,n)&&(a[l++]=n[r]);else for(;++r!==o;)r in this&&e.call(t,n[r],r,n)&&(a[l++]=n[r]);return a.length=l,a})},,,,function(e,t,o){"use strict";o.r(t);var a=function(){const e=jQuery,t=()=>weglot_languages.available.filter(e=>e.code!==weglot_languages.original);let o;const a=()=>{let a=e("#original_language").val();e("#original_language").on("change",function(t){const n=a,l=a;a=t.target.value,o[0].selectize.removeOption(a);const r=weglot_languages.available.find(e=>e.code===l),s=weglot_languages.available.find(e=>e.code===a);o[0].selectize.addOption(r);const c=e("#is_fullname").is(":checked");let i="";e("#with_name").is(":checked")&&(i=c?s.local:s.code.toUpperCase()),e(".wgcurrent.wg-li").removeClass(n).addClass(a).attr("data-code-language",a).find("span").html(i)}),o=e(".weglot-select-destination").selectize({delimiter:"|",persist:!1,valueField:"code",labelField:"local",searchField:["code","english","local"],sortField:[{field:"english",direction:"asc"}],maxItems:weglot_languages.limit,plugins:["remove_button","drag_drop"],options:t(),render:{option:function(e,t){return'<div class="weglot__choice__language"><span class="weglot__choice__language--english">'+t(e.english)+'</span><span class="weglot__choice__language--local">'+t(e.local)+" ["+t(e.code)+"]</span></div>"}}}).on("change",t=>{const a=o[0].selectize.getValue(),n=e("#li-button-tpl");if(0===n.length)return;const l=e("#is_fullname").is(":checked"),r=e("#with_name").is(":checked"),s=e("#with_flags").is(":checked");let c="";s&&(c="weglot-flags");let i="";a.forEach(e=>{const t=weglot_languages.available.find(t=>t.code===e);let o="";r&&(o=l?t.local:e.toUpperCase()),i+=n.html().replace("{LABEL_LANGUAGE}",o).replace(new RegExp("{CODE_LANGUAGE}","g"),e).replace("{CLASSES}",c)}),e(".country-selector ul").html(i)}),window.addEventListener("weglotCheckApi",e=>{let t=1e3;const a=e.detail.plan;a<=0||weglot_languages.plans.starter_free.ids.indexOf(a)>=0?t=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(a)>=0&&(t=weglot_languages.plans.business.limit_language),o[0].selectize.settings.maxItems=t})};document.addEventListener("DOMContentLoaded",()=>{a()})};var n=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{e("#weglot-box-first-settings .weglot-btn-close").on("click",function(t){t.preventDefault(),e("#weglot-box-first-settings").hide()})})};var l=function(){const e=()=>{document.querySelector("#tpl-exclusion-url");const e=document.querySelector("#tpl-exclusion-block"),t=document.querySelector("#container-exclude_blocks");function o(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",a=>{a.preventDefault(),t.insertAdjacentHTML("beforeend",e.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",o)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",o)})};document.addEventListener("DOMContentLoaded",()=>{e()})};var r=function(){const e=jQuery,t=()=>{let t=e("#type_flags option:selected").data("value"),o=[];o.push(e(".country-selector label").data("code-language")),e(".country-selector li").each((t,a)=>{o.push(e(a).data("code-language"))});const a=weglot_languages.available.filter(e=>o.indexOf(e.code)>=0);e("#weglot-css-inline").text(weglot_css.inline),e("#is_dropdown").on("change",function(){e(".country-selector").toggleClass("weglot-inline"),e(".country-selector").toggleClass("weglot-dropdown")}),e("#with_flags").on("change",function(){e(".country-selector label, .country-selector li").toggleClass("weglot-flags")}),e("#type_flags").on("change",function(o){e(".country-selector label, .country-selector li").removeClass(`flag-${t}`);const a=e(":selected",this).data("value");e(".country-selector label, .country-selector li").addClass(`flag-${a}`),t=a});const n=()=>{const t=a.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),n=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(n),e(".country-selector li").each((t,n)=>{const l=a.find(t=>t.code===e(n).data("code-language")),r=o?l.local:l.code.toUpperCase();e(n).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?n():(e(".country-selector label a, .country-selector label span").text(""),e(".country-selector li a, .country-selector li span").each((t,o)=>{e(o).text("")}))}),e("#is_fullname").on("change",function(t){if(e("#with_name").is(":checked"))if(t.target.checked)n();else{const t=a.find(t=>t.code===e(".country-selector label").data("code-language"));e(".country-selector label a, .country-selector label span").text(t.code.toUpperCase()),e(".country-selector li").each((t,o)=>{const n=a.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(n.code.toUpperCase()),e(o).find("span").text(n.code.toUpperCase())})}}),e("#override_css").on("keyup",function(t){e("#weglot-css-inline").text(t.target.value)})};document.addEventListener("DOMContentLoaded",()=>{0!==e(".weglot-preview").length&&t()})};var s=function(){const e=jQuery,t=()=>{e("#api_key_private").blur(function(){var t=e(this).val();if(0===t.length)return e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>'),void e("#wrap-weglot #submit").prop("disabled",!0);function o(){e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!0)}e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-ckeckkey"></span>'),e.ajax({method:"POST",url:ajaxurl,data:{action:"get_user_info",api_key:t},success:({data:t,success:a})=>{e(".weglot-keyres").remove(),a?function(t){e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-okkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!1);const o=new CustomEvent("weglotCheckApi",{detail:t});window.dispatchEvent(o)}(t):o()}}).fail(function(){o()})})};document.addEventListener("DOMContentLoaded",()=>{t()})};var c=function(){jQuery;document.addEventListener("DOMContentLoaded",()=>{jQuery(document).ready(function(e){wp.codeEditor.initialize(e("#override_css"),cm_settings)})})};var i=function(){const e=jQuery;"undefined"!=typeof weglot_css&&e("#weglot-css-flag-css").text(weglot_css.flag_css);const t=()=>{e(".flag-style-openclose").on("click",function(){e(".flag-style-wrapper").toggle()}),e("select.flag-en-type, select.flag-es-type, select.flag-pt-type, select.flag-fr-type, select.flag-ar-type").on("change",function(){!function(){var t=new Array,o=new Array,a=new Array,n=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],a[1]=[1740,5921,528,3504],n[1]=[2760,736,2856,4416],n[2]=[3840,1280,2712,4224],n[3]=[5700,7201,5016,2400],n[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; } ",d=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; } ",u=c<=0?"":".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -"+a[c][0]+"px 0 !important; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -"+a[c][1]+"px 0 !important; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -"+a[c][2]+"px 0 !important; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -"+a[c][3]+"px 0 !important; } ",p=i<=0?"":".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -"+n[i][0]+"px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -"+n[i][1]+"px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -"+n[i][2]+"px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -"+n[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+d+u+p+w)}()})};document.addEventListener("DOMContentLoaded",()=>{t()})};var g=function(){jQuery;document.addEventListener("DOMContentLoaded",()=>{const e=document.querySelector("#private_mode");e&&0!=e.length&&(document.querySelector("#private_mode").addEventListener("change",function(e){document.querySelectorAll(".private-mode-lang--input").forEach(t=>{t.checked=e.target.checked})}),document.querySelectorAll(".private-mode-lang--input").forEach(e=>{e.addEventListener("change",function(e){0===document.querySelectorAll(".private-mode-lang--input:checked").length&&(document.querySelector("#private_mode").checked=!1)})}))})};o(0),o(1);a(),l(),n(),r(),s(),c(),i(),g()}]);
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: translate, multilingual, language, translation, localization
4
  Requires at least: 4.5
5
  Tested up to: 5.4
6
  Requires PHP: 5.4
7
- Stable tag: 3.1.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -201,6 +201,15 @@ See changelog for upgrade changes.
201
 
202
  == Changelog ==
203
 
 
 
 
 
 
 
 
 
 
204
  = 3.1.7 (04/05/2020) =
205
  * Add a Weglot Menu to admin bar
206
  * Add Woocommerce feature : Translate following mail
4
  Requires at least: 4.5
5
  Tested up to: 5.4
6
  Requires PHP: 5.4
7
+ Stable tag: 3.1.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
201
 
202
  == Changelog ==
203
 
204
+ = 3.1.8 (02/07/2020) =
205
+ * Exclude URL by languages
206
+ * Translate by default all Woocommerce mails with customer language
207
+ * Update URLs translation, possibility to use custom URLs for hierarchical pages
208
+ * Translate External URLs
209
+ * Add SVG files to media translation
210
+ * Exclude wp-cron.php from translation
211
+ * Fix links translation with custom URLS
212
+
213
  = 3.1.7 (04/05/2020) =
214
  * Add a Weglot Menu to admin bar
215
  * Add Woocommerce feature : Translate following mail
src/actions/admin/class-admin-enqueue-weglot.php CHANGED
@@ -34,9 +34,9 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
34
  * @return void
35
  */
36
  public function hooks() {
37
- add_action( 'admin_enqueue_scripts', [ $this, 'weglot_admin_enqueue_scripts' ] );
38
- add_action( 'admin_enqueue_scripts', [ $this, 'weglot_admin_enqueue_scripts_metaboxes' ] );
39
- add_action( 'admin_head', [ $this, 'weglot_admin_print_head' ] );
40
  }
41
 
42
  /**
@@ -50,8 +50,8 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
50
  return;
51
  }
52
 
53
- wp_enqueue_script( 'weglot-admin-metaboxes-js', WEGLOT_URL_DIST . '/metaboxes-js.js', [ 'jquery' ] );
54
- wp_enqueue_style( 'weglot-admin-css', WEGLOT_URL_DIST . '/css/admin-css.css', [], WEGLOT_VERSION );
55
  }
56
 
57
 
@@ -64,13 +64,13 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
64
  * @return void
65
  */
66
  public function weglot_admin_enqueue_scripts( $page ) {
67
- if ( ! in_array( $page, [ 'toplevel_page_' . Helper_Pages_Weglot::SETTINGS ], true ) ) {
68
  return;
69
  }
70
 
71
- wp_enqueue_script( 'weglot-admin-selectize-js', WEGLOT_URL_DIST . '/selectize.js', [ 'jquery', 'jquery-ui-sortable' ] );
72
 
73
- wp_enqueue_script( 'weglot-admin', WEGLOT_URL_DIST . '/admin-js.js', [ 'weglot-admin-selectize-js' ], WEGLOT_VERSION );
74
 
75
  $user_info = $this->user_api_services->get_user_info();
76
  $plans = $this->user_api_services->get_plans();
@@ -92,13 +92,13 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
92
  wp_localize_script(
93
  'weglot-admin',
94
  'weglot_languages',
95
- [
96
  'available' => json_decode(
97
  json_encode(
98
  $this->language_services->get_languages_available(
99
- [
100
  'sort' => true,
101
- ]
102
  ),
103
  true
104
  ),
@@ -107,19 +107,19 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
107
  'limit' => $limit,
108
  'plans' => $this->user_api_services->get_plans(),
109
  'original' => weglot_get_original_language(),
110
- ]
111
  );
112
 
113
- wp_enqueue_style( 'weglot-admin-css', WEGLOT_URL_DIST . '/css/admin-css.css', [], WEGLOT_VERSION );
114
 
115
- wp_enqueue_style( 'weglot-css', WEGLOT_URL_DIST . '/css/front-css.css', [], WEGLOT_VERSION );
116
  wp_localize_script(
117
  'weglot-admin',
118
  'weglot_css',
119
- [
120
  'inline' => $this->option_services->get_css_custom_inline(),
121
  'flag_css' => $this->option_services->get_option( 'flag_css' ),
122
- ]
123
  );
124
 
125
  /**
34
  * @return void
35
  */
36
  public function hooks() {
37
+ add_action( 'admin_enqueue_scripts', array( $this, 'weglot_admin_enqueue_scripts' ) );
38
+ add_action( 'admin_enqueue_scripts', array( $this, 'weglot_admin_enqueue_scripts_metaboxes' ) );
39
+ add_action( 'admin_head', array( $this, 'weglot_admin_print_head' ) );
40
  }
41
 
42
  /**
50
  return;
51
  }
52
 
53
+ wp_enqueue_script( 'weglot-admin-metaboxes-js', WEGLOT_URL_DIST . '/metaboxes-js.js', array( 'jquery' ) );
54
+ wp_enqueue_style( 'weglot-admin-css', WEGLOT_URL_DIST . '/css/admin-css.css', array(), WEGLOT_VERSION );
55
  }
56
 
57
 
64
  * @return void
65
  */
66
  public function weglot_admin_enqueue_scripts( $page ) {
67
+ if ( ! in_array( $page, array( 'toplevel_page_' . Helper_Pages_Weglot::SETTINGS ), true ) ) {
68
  return;
69
  }
70
 
71
+ wp_enqueue_script( 'weglot-admin-selectize-js', WEGLOT_URL_DIST . '/selectize.js', array( 'jquery', 'jquery-ui-sortable' ) );
72
 
73
+ wp_enqueue_script( 'weglot-admin', WEGLOT_URL_DIST . '/admin-js.js', array( 'weglot-admin-selectize-js' ), WEGLOT_VERSION );
74
 
75
  $user_info = $this->user_api_services->get_user_info();
76
  $plans = $this->user_api_services->get_plans();
92
  wp_localize_script(
93
  'weglot-admin',
94
  'weglot_languages',
95
+ array(
96
  'available' => json_decode(
97
  json_encode(
98
  $this->language_services->get_languages_available(
99
+ array(
100
  'sort' => true,
101
+ )
102
  ),
103
  true
104
  ),
107
  'limit' => $limit,
108
  'plans' => $this->user_api_services->get_plans(),
109
  'original' => weglot_get_original_language(),
110
+ )
111
  );
112
 
113
+ wp_enqueue_style( 'weglot-admin-css', WEGLOT_URL_DIST . '/css/admin-css.css', array(), WEGLOT_VERSION );
114
 
115
+ wp_enqueue_style( 'weglot-css', WEGLOT_URL_DIST . '/css/front-css.css', array(), WEGLOT_VERSION );
116
  wp_localize_script(
117
  'weglot-admin',
118
  'weglot_css',
119
+ array(
120
  'inline' => $this->option_services->get_css_custom_inline(),
121
  'flag_css' => $this->option_services->get_option( 'flag_css' ),
122
+ )
123
  );
124
 
125
  /**
src/actions/admin/class-ajax-user-info.php CHANGED
@@ -24,7 +24,7 @@ class Ajax_User_Info implements Hooks_Interface_Weglot {
24
  return;
25
  }
26
 
27
- add_action( 'wp_ajax_get_user_info', [ $this, 'get_user_info' ] );
28
  }
29
 
30
  /**
24
  return;
25
  }
26
 
27
+ add_action( 'wp_ajax_get_user_info', array( $this, 'get_user_info' ) );
28
  }
29
 
30
  /**
src/actions/admin/class-customize-menu-weglot.php CHANGED
@@ -20,12 +20,12 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
20
  * @since 2.0
21
  */
22
  public function __construct() {
23
- $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
24
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
26
- $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
27
- $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
28
- $this->menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
29
  return $this;
30
  }
31
 
@@ -38,9 +38,9 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
38
  */
39
  public function hooks() {
40
 
41
- add_action( 'admin_head-nav-menus.php', [ $this, 'add_nav_menu_meta_boxes' ] );
42
- add_action( 'admin_enqueue_scripts', [ $this, 'nav_admin_enqueue_scripts' ] );
43
- add_action( 'wp_update_nav_menu_item', [ $this, 'custom_wp_update_nav_menu_item' ], 10, 2 );
44
  }
45
 
46
 
@@ -65,7 +65,7 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
65
 
66
  $options_menu = $this->option_services->get_option( 'menu_switcher' );
67
  if ( ! $options_menu ) {
68
- $options_menu = [];
69
  }
70
 
71
  if ( array_key_exists( 'menu-item-weglot-dropdown', $_POST ) ) {
@@ -94,11 +94,11 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
94
  return;
95
  }
96
 
97
- wp_enqueue_script( 'weglot_nav_menu', WEGLOT_URL_DIST . '/nav-js.js', [ 'jquery' ], WEGLOT_VERSION );
98
 
99
- $data['title'] = 'Weglot switcher'; // No translate this!
100
- $data['options'] = $this->option_services->get_option_by_key_v3( 'menu_switcher' );
101
- $data['list_options'] = $this->menu_options_services->get_list_options_menu_switcher();
102
 
103
  wp_localize_script( 'weglot_nav_menu', 'weglot_data', $data );
104
  }
@@ -111,7 +111,7 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
111
  * @return void
112
  */
113
  public function add_nav_menu_meta_boxes() {
114
- add_meta_box( 'weglot_nav_link', __( 'Weglot switcher', 'weglot' ), [ $this, 'nav_menu_links' ], 'nav-menus', 'side', 'low' );
115
  }
116
 
117
  /**
20
  * @since 2.0
21
  */
22
  public function __construct() {
23
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
24
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
26
+ $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
27
+ $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
28
+ $this->menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
29
  return $this;
30
  }
31
 
38
  */
39
  public function hooks() {
40
 
41
+ add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
42
+ add_action( 'admin_enqueue_scripts', array( $this, 'nav_admin_enqueue_scripts' ) );
43
+ add_action( 'wp_update_nav_menu_item', array( $this, 'custom_wp_update_nav_menu_item' ), 10, 2 );
44
  }
45
 
46
 
65
 
66
  $options_menu = $this->option_services->get_option( 'menu_switcher' );
67
  if ( ! $options_menu ) {
68
+ $options_menu = array();
69
  }
70
 
71
  if ( array_key_exists( 'menu-item-weglot-dropdown', $_POST ) ) {
94
  return;
95
  }
96
 
97
+ wp_enqueue_script( 'weglot_nav_menu', WEGLOT_URL_DIST . '/nav-js.js', array( 'jquery' ), WEGLOT_VERSION );
98
 
99
+ $data['title'] = 'Weglot switcher'; // No translate this!
100
+ $data['options'] = $this->option_services->get_option_by_key_v3( 'menu_switcher' );
101
+ $data['list_options'] = $this->menu_options_services->get_list_options_menu_switcher();
102
 
103
  wp_localize_script( 'weglot_nav_menu', 'weglot_data', $data );
104
  }
111
  * @return void
112
  */
113
  public function add_nav_menu_meta_boxes() {
114
+ add_meta_box( 'weglot_nav_link', __( 'Weglot switcher', 'weglot' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' );
115
  }
116
 
117
  /**
src/actions/admin/class-metabox-url-translate-weglot.php CHANGED
@@ -21,8 +21,8 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
21
  * @since 2.1.0
22
  */
23
  public function __construct() {
24
- $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
25
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
26
  }
27
 
28
  /**
@@ -32,13 +32,13 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
32
  * @return void
33
  */
34
  public function hooks() {
35
- add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes_url_translate' ] );
36
- add_action( 'save_post', [ $this, 'save_post_meta_boxes_url_translate' ], 10, 3 );
37
- add_action( 'wp_ajax_weglot_post_name', [ $this, 'weglot_post_name' ] );
38
- add_action( 'wp_ajax_weglot_reset_custom_url', [ $this, 'weglot_reset_custom_url' ] );
39
 
40
- add_filter( 'wp_insert_post_data', [ $this, 'weglot_wp_insert_post_data' ], 10, 2 );
41
- add_filter( 'wp_unique_post_slug', [ $this, 'weglot_wp_unique_post_slug' ] );
42
  }
43
 
44
  /**
@@ -53,16 +53,18 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
53
  ! isset( $_POST['custom_url'] ) || //phpcs:ignore
54
  ! isset( $_POST['id'] ) //phpcs:ignore
55
  ) {
56
- wp_send_json_error( [
57
- 'code' => 'missing_parameter',
58
- ] );
 
 
59
  return;
60
  }
61
 
62
- $code_lang = sanitize_text_field( wp_unslash( $_POST['code_lang'] ) ); //phpcs:ignore
63
- $post_name_weglot = sanitize_text_field( wp_unslash( $_POST['custom_url'] ) ); //phpcs:ignore
64
 
65
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
66
 
67
  if ( isset( $custom_urls[ $code_lang ] ) && isset( $custom_urls[ $code_lang ][ $post_name_weglot ] ) ) {
68
  unset( $custom_urls[ $code_lang ] [ $post_name_weglot ] );
@@ -71,11 +73,13 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
71
 
72
  $post = get_post( $_POST['id'] ); //phpcs:ignore
73
 
74
- wp_send_json_success( [
75
- 'result' => [
76
- 'slug' => $post->post_name,
77
- ],
78
- ] );
 
 
79
  }
80
 
81
  /**
@@ -89,7 +93,7 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
89
  protected function search_unique_key_post_name( $slug, $custom_urls, $suffix = 2 ) {
90
  foreach ( $custom_urls as $key_code => $urls ) {
91
  if ( isset( $urls[ $slug ] ) ) {
92
- $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
93
  return $this->search_unique_key_post_name( $alt_post_name, $custom_urls, ++$suffix );
94
  }
95
  }
@@ -103,7 +107,7 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
103
  *
104
  * @since 2.1.0
105
  *
106
- * @param string $slug The post slug.
107
  */
108
  public function weglot_wp_unique_post_slug( $slug ) {
109
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
@@ -117,36 +121,42 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
117
  */
118
  public function weglot_post_name() {
119
  $weglot_post_name = ( isset( $_POST['post_name'] ) && ! empty( $_POST['post_name'] ) ) ? sanitize_title( $_POST['post_name'] ) : null ; //phpcs:ignore
120
- $code_language = ( isset( $_POST['lang'] ) && ! empty( $_POST['lang'] ) ) ? sanitize_text_field( $_POST['lang'] ) : null ; //phpcs:ignore
121
- $post_id = ( isset( $_POST['id'] ) && ! empty( $_POST['id'] ) ) ? sanitize_text_field( $_POST['id'] ) : null ; //phpcs:ignore
122
 
123
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
124
 
125
  if ( ! $weglot_post_name || ! $code_language || ! $post_id ) {
126
- wp_send_json_error( [
127
- 'success' => false,
128
- 'code' => 'missing_parameter',
129
- ] );
 
 
130
  return;
131
  }
132
 
133
  // Check if not an autosave.
134
  if ( wp_is_post_autosave( $post_id ) ) {
135
- wp_send_json_error( [
136
- 'success' => false,
137
- ] );
 
 
138
  return;
139
  }
140
 
141
  // Check if not a revision.
142
  if ( wp_is_post_revision( $post_id ) ) {
143
- wp_send_json_error( [
144
- 'success' => false,
145
- ] );
 
 
146
  return;
147
  }
148
 
149
- $post = get_post( $post_id );
150
  if ( $post->post_name === $weglot_post_name ) {
151
  if ( in_array( $post->post_name, $custom_urls[ $code_language ] ) ) { // phpcs:ignore
152
  $key_post_name = array_search( $post->post_name, $custom_urls[ $code_language ] );// phpcs:ignore
@@ -154,18 +164,22 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
154
 
155
  $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
156
 
157
- wp_send_json_success( [
158
- 'success' => true,
159
- 'result' => [
160
- 'slug' => $weglot_post_name,
161
- ],
162
- ] );
 
 
163
  return;
164
  }
165
 
166
- wp_send_json_success( [
167
- 'code' => 'same_post_name',
168
- ] );
 
 
169
 
170
  return;
171
  }
@@ -173,9 +187,11 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
173
  if ( isset( $custom_urls[ $code_language ] ) ) {
174
  // Same use
175
  if ( isset( $custom_urls[ $code_language ][ $weglot_post_name ] ) && $custom_urls[ $code_language ][ $weglot_post_name ] === $post->post_name ) {
176
- wp_send_json_success( [
177
- 'code' => 'same_post_name',
178
- ] );
 
 
179
  return;
180
  }
181
 
@@ -190,12 +206,14 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
190
  $custom_urls[ $code_language ] [ $weglot_unique_slug ] = $post->post_name;
191
  $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
192
 
193
- wp_send_json_success( [
194
- 'success' => true,
195
- 'result' => [
196
- 'slug' => $weglot_unique_slug,
197
- ],
198
- ] );
 
 
199
  }
200
 
201
  /**
@@ -210,17 +228,22 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
210
 
211
  $post_type = get_post_type();
212
 
213
- $exclude_post_type_metabox = apply_filters( 'weglot_url_translate_metabox_post_type_exclude', [
214
- 'attachment',
215
- 'seopress_404',
216
- 'product',
217
- ] );
 
 
 
 
 
218
 
219
  if ( in_array( $post_type, $exclude_post_type_metabox ) ) { //phpcs:ignore
220
  return;
221
  }
222
 
223
- add_meta_box( 'weglot-url-translate', __( 'Weglot URL Translate', 'weglot' ), [ $this, 'weglot_url_translate_box' ] );
224
  }
225
 
226
  /**
@@ -263,7 +286,7 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
263
  public function save_post_meta_boxes_url_translate( $post_id, $post, $update ) {
264
 
265
  // Add nonce for security and authentication.
266
- $post_name_weglot = isset( $_POST[ Helper_Post_Meta_Weglot::POST_NAME_WEGLOT ] ) ? $_POST[ Helper_Post_Meta_Weglot::POST_NAME_WEGLOT ] : []; //phpcs:ignore
267
 
268
  if ( ! isset( $post_name_weglot ) ) {
269
  return;
@@ -284,7 +307,7 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
284
  return;
285
  }
286
 
287
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
288
 
289
  // Update new post_name
290
  if ( $this->old_post_name !== $this->new_post_name ) {
21
  * @since 2.1.0
22
  */
23
  public function __construct() {
24
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
25
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
26
  }
27
 
28
  /**
32
  * @return void
33
  */
34
  public function hooks() {
35
+ add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes_url_translate' ) );
36
+ add_action( 'save_post', array( $this, 'save_post_meta_boxes_url_translate' ), 10, 3 );
37
+ add_action( 'wp_ajax_weglot_post_name', array( $this, 'weglot_post_name' ) );
38
+ add_action( 'wp_ajax_weglot_reset_custom_url', array( $this, 'weglot_reset_custom_url' ) );
39
 
40
+ add_filter( 'wp_insert_post_data', array( $this, 'weglot_wp_insert_post_data' ), 10, 2 );
41
+ add_filter( 'wp_unique_post_slug', array( $this, 'weglot_wp_unique_post_slug' ) );
42
  }
43
 
44
  /**
53
  ! isset( $_POST['custom_url'] ) || //phpcs:ignore
54
  ! isset( $_POST['id'] ) //phpcs:ignore
55
  ) {
56
+ wp_send_json_error(
57
+ array(
58
+ 'code' => 'missing_parameter',
59
+ )
60
+ );
61
  return;
62
  }
63
 
64
+ $code_lang = sanitize_text_field( wp_unslash( $_POST['code_lang'] ) ); //phpcs:ignore
65
+ $post_name_weglot = sanitize_text_field( wp_unslash( $_POST['custom_url'] ) ); //phpcs:ignore
66
 
67
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
68
 
69
  if ( isset( $custom_urls[ $code_lang ] ) && isset( $custom_urls[ $code_lang ][ $post_name_weglot ] ) ) {
70
  unset( $custom_urls[ $code_lang ] [ $post_name_weglot ] );
73
 
74
  $post = get_post( $_POST['id'] ); //phpcs:ignore
75
 
76
+ wp_send_json_success(
77
+ array(
78
+ 'result' => array(
79
+ 'slug' => $post->post_name,
80
+ ),
81
+ )
82
+ );
83
  }
84
 
85
  /**
93
  protected function search_unique_key_post_name( $slug, $custom_urls, $suffix = 2 ) {
94
  foreach ( $custom_urls as $key_code => $urls ) {
95
  if ( isset( $urls[ $slug ] ) ) {
96
+ $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
97
  return $this->search_unique_key_post_name( $alt_post_name, $custom_urls, ++$suffix );
98
  }
99
  }
107
  *
108
  * @since 2.1.0
109
  *
110
+ * @param string $slug The post slug.
111
  */
112
  public function weglot_wp_unique_post_slug( $slug ) {
113
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
121
  */
122
  public function weglot_post_name() {
123
  $weglot_post_name = ( isset( $_POST['post_name'] ) && ! empty( $_POST['post_name'] ) ) ? sanitize_title( $_POST['post_name'] ) : null ; //phpcs:ignore
124
+ $code_language = ( isset( $_POST['lang'] ) && ! empty( $_POST['lang'] ) ) ? sanitize_text_field( $_POST['lang'] ) : null ; //phpcs:ignore
125
+ $post_id = ( isset( $_POST['id'] ) && ! empty( $_POST['id'] ) ) ? sanitize_text_field( $_POST['id'] ) : null ; //phpcs:ignore
126
 
127
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
128
 
129
  if ( ! $weglot_post_name || ! $code_language || ! $post_id ) {
130
+ wp_send_json_error(
131
+ array(
132
+ 'success' => false,
133
+ 'code' => 'missing_parameter',
134
+ )
135
+ );
136
  return;
137
  }
138
 
139
  // Check if not an autosave.
140
  if ( wp_is_post_autosave( $post_id ) ) {
141
+ wp_send_json_error(
142
+ array(
143
+ 'success' => false,
144
+ )
145
+ );
146
  return;
147
  }
148
 
149
  // Check if not a revision.
150
  if ( wp_is_post_revision( $post_id ) ) {
151
+ wp_send_json_error(
152
+ array(
153
+ 'success' => false,
154
+ )
155
+ );
156
  return;
157
  }
158
 
159
+ $post = get_post( $post_id );
160
  if ( $post->post_name === $weglot_post_name ) {
161
  if ( in_array( $post->post_name, $custom_urls[ $code_language ] ) ) { // phpcs:ignore
162
  $key_post_name = array_search( $post->post_name, $custom_urls[ $code_language ] );// phpcs:ignore
164
 
165
  $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
166
 
167
+ wp_send_json_success(
168
+ array(
169
+ 'success' => true,
170
+ 'result' => array(
171
+ 'slug' => $weglot_post_name,
172
+ ),
173
+ )
174
+ );
175
  return;
176
  }
177
 
178
+ wp_send_json_success(
179
+ array(
180
+ 'code' => 'same_post_name',
181
+ )
182
+ );
183
 
184
  return;
185
  }
187
  if ( isset( $custom_urls[ $code_language ] ) ) {
188
  // Same use
189
  if ( isset( $custom_urls[ $code_language ][ $weglot_post_name ] ) && $custom_urls[ $code_language ][ $weglot_post_name ] === $post->post_name ) {
190
+ wp_send_json_success(
191
+ array(
192
+ 'code' => 'same_post_name',
193
+ )
194
+ );
195
  return;
196
  }
197
 
206
  $custom_urls[ $code_language ] [ $weglot_unique_slug ] = $post->post_name;
207
  $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
208
 
209
+ wp_send_json_success(
210
+ array(
211
+ 'success' => true,
212
+ 'result' => array(
213
+ 'slug' => $weglot_unique_slug,
214
+ ),
215
+ )
216
+ );
217
  }
218
 
219
  /**
228
 
229
  $post_type = get_post_type();
230
 
231
+ $exclude_post_type_metabox = apply_filters(
232
+ 'weglot_url_translate_metabox_post_type_exclude',
233
+ array(
234
+ 'attachment',
235
+ 'seopress_404',
236
+ 'product',
237
+ 'shop_order',
238
+ 'shop_coupon',
239
+ )
240
+ );
241
 
242
  if ( in_array( $post_type, $exclude_post_type_metabox ) ) { //phpcs:ignore
243
  return;
244
  }
245
 
246
+ add_meta_box( 'weglot-url-translate', __( 'Weglot URL Translate', 'weglot' ), array( $this, 'weglot_url_translate_box' ) );
247
  }
248
 
249
  /**
286
  public function save_post_meta_boxes_url_translate( $post_id, $post, $update ) {
287
 
288
  // Add nonce for security and authentication.
289
+ $post_name_weglot = isset( $_POST[ Helper_Post_Meta_Weglot::POST_NAME_WEGLOT ] ) ? $_POST[ Helper_Post_Meta_Weglot::POST_NAME_WEGLOT ] : []; //phpcs:ignore
290
 
291
  if ( ! isset( $post_name_weglot ) ) {
292
  return;
307
  return;
308
  }
309
 
310
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
311
 
312
  // Update new post_name
313
  if ( $this->old_post_name !== $this->new_post_name ) {
src/actions/admin/class-options-weglot.php CHANGED
@@ -9,7 +9,6 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
10
  use WeglotWP\Helpers\Helper_Pages_Weglot;
11
  use WeglotWP\Helpers\Helper_Flag_Type;
12
-
13
  use WeglotWP\Models\Hooks_Interface_Weglot;
14
 
15
  /**
@@ -35,11 +34,11 @@ class Options_Weglot implements Hooks_Interface_Weglot {
35
  * @return void
36
  */
37
  public function hooks() {
38
- add_action( 'admin_post_weglot_save_settings', [ $this, 'weglot_save_settings' ] );
39
  $api_key = $this->option_services->get_api_key( true );
40
  if ( empty( $api_key ) && ( ! isset( $_GET['page'] ) || strpos( $_GET['page'], 'weglot-settings' ) === false) ) { // phpcs:ignore
41
  //We don't show the notice if we are on Weglot configuration
42
- add_action( 'admin_notices', [ '\WeglotWP\Notices\No_Configuration_Weglot', 'admin_notice' ] );
43
  }
44
  }
45
 
@@ -69,20 +68,19 @@ class Options_Weglot implements Hooks_Interface_Weglot {
69
  return;
70
  }
71
 
72
- $tab = $_GET[ 'tab' ]; //phpcs:ignore
73
- $options = $_POST[ WEGLOT_SLUG ]; //phpcs:ignore
74
  $options_bdd = $this->option_services->get_options_bdd_v3();
75
  switch ( $tab ) {
76
  case Helper_Tabs_Admin_Weglot::SETTINGS:
77
-
78
  $has_first_settings = $this->option_services->get_has_first_settings();
79
  $options = $this->sanitize_options_settings( $options, $has_first_settings );
80
- $response = $this->option_services->save_options_to_weglot( $options, $has_first_settings );
81
 
82
  if ( $response['success'] ) {
83
  delete_transient( 'weglot_cache_cdn' );
84
 
85
- $api_key_private = $this->option_services->get_api_key_private();
86
 
87
  $option_v2 = $this->option_services->get_options_from_v2();
88
  if ( ! $api_key_private && $option_v2 ) {
@@ -110,23 +108,21 @@ class Options_Weglot implements Hooks_Interface_Weglot {
110
  case Helper_Tabs_Admin_Weglot::SUPPORT:
111
  if ( array_key_exists( 'active_wc_reload', $options ) && $options['active_wc_reload'] === 'on' ) {
112
  $options_bdd['active_wc_reload'] = true;
113
- }
114
- else {
115
  $options_bdd['active_wc_reload'] = false;
116
  }
117
 
118
  $this->option_services->set_options( $options_bdd );
119
  break;
120
  case Helper_Tabs_Admin_Weglot::CUSTOM_URLS:
121
- if (null === $options_bdd) {
122
- $options_bdd['custom_urls'] = [];
123
  }
124
 
125
  if ( array_key_exists( 'custom_urls', $options ) ) {
126
  $options_bdd['custom_urls'] = $options['custom_urls'];
127
- }
128
- else {
129
- $options_bdd['custom_urls'] = [];
130
  }
131
 
132
  $this->option_services->set_options( $options_bdd );
@@ -145,8 +141,8 @@ class Options_Weglot implements Hooks_Interface_Weglot {
145
  * @return array
146
  */
147
  public function sanitize_options_settings( $options, $has_first_settings = false ) {
148
- $user_info = $this->user_api_services->get_user_info( $options['api_key_private'] );
149
- $plans = $this->user_api_services->get_plans();
150
 
151
  // Limit language
152
  if (
@@ -162,10 +158,10 @@ class Options_Weglot implements Hooks_Interface_Weglot {
162
 
163
  $default_options = $this->option_services->get_options_default();
164
 
165
- $options['custom_settings']['button_style']['is_dropdown'] = isset( $options['custom_settings']['button_style']['is_dropdown'] );
166
- $options['custom_settings']['button_style']['with_flags'] = isset( $options['custom_settings']['button_style']['with_flags'] );
167
- $options['custom_settings']['button_style']['full_name'] = isset( $options['custom_settings']['button_style']['full_name'] );
168
- $options['custom_settings']['button_style']['with_name'] = isset( $options['custom_settings']['button_style']['with_name'] );
169
 
170
  if ( $has_first_settings ) {
171
  $options['custom_settings']['button_style']['is_dropdown'] = $default_options['custom_settings']['button_style']['is_dropdown'];
@@ -174,15 +170,15 @@ class Options_Weglot implements Hooks_Interface_Weglot {
174
  $options['custom_settings']['button_style']['with_name'] = $default_options['custom_settings']['button_style']['with_name'];
175
  }
176
 
177
- $options['custom_settings']['button_style']['custom_css'] = isset( $options['custom_settings']['button_style']['custom_css'] ) ? stripcslashes( $options['custom_settings']['button_style']['custom_css'] ) : '';
178
 
179
- $options['custom_settings']['button_style']['flag_type'] = isset( $options['custom_settings']['button_style']['flag_type'] ) ? $options['custom_settings']['button_style']['flag_type'] : Helper_Flag_Type::RECTANGLE_MAT;
180
 
181
- $options['custom_settings']['translate_email'] = isset( $options['custom_settings']['translate_email'] );
182
- $options['custom_settings']['translate_search'] = isset( $options['custom_settings']['translate_search'] );
183
- $options['custom_settings']['translate_amp'] = isset( $options['custom_settings']['translate_amp'] );
184
 
185
- $options['auto_switch'] = isset( $options['auto_switch'] );
186
  foreach ( $options['languages'] as $key => $language ) {
187
  if ( 'active' === $key ) {
188
  continue;
@@ -190,29 +186,17 @@ class Options_Weglot implements Hooks_Interface_Weglot {
190
  $options['languages'][ $key ]['enabled'] = ! isset( $options['languages'][ $key ]['enabled'] );
191
  }
192
 
193
- if ( ! isset( $options['excluded_paths'] ) ) {
194
- $options['excluded_paths'] = [];
195
- } else {
196
- $options['excluded_paths'] = array_values( $options['excluded_paths'] );
197
- }
198
-
199
- foreach ( $options['excluded_paths'] as $key => $item ) {
200
- if ( empty( $item['value'] ) ) {
201
- unset( $options['excluded_paths'][ $key ] );
202
- }
203
- else {
204
- $options['excluded_paths'][ $key ]['value'] = stripcslashes( $item['value'] );
205
- }
206
- }
207
-
208
  if ( ! isset( $options['excluded_blocks'] ) ) {
209
- $options['excluded_blocks'] = [];
 
 
 
 
 
 
 
 
210
  }
211
- else {
212
- array_walk_recursive( $options['excluded_blocks'], function ( &$element ) { //We remove unwanted backslashes
213
- $element = stripslashes( $element );
214
- } );
215
- }
216
 
217
  return $options;
218
  }
9
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
10
  use WeglotWP\Helpers\Helper_Pages_Weglot;
11
  use WeglotWP\Helpers\Helper_Flag_Type;
 
12
  use WeglotWP\Models\Hooks_Interface_Weglot;
13
 
14
  /**
34
  * @return void
35
  */
36
  public function hooks() {
37
+ add_action( 'admin_post_weglot_save_settings', array( $this, 'weglot_save_settings' ) );
38
  $api_key = $this->option_services->get_api_key( true );
39
  if ( empty( $api_key ) && ( ! isset( $_GET['page'] ) || strpos( $_GET['page'], 'weglot-settings' ) === false) ) { // phpcs:ignore
40
  //We don't show the notice if we are on Weglot configuration
41
+ add_action( 'admin_notices', array( '\WeglotWP\Notices\No_Configuration_Weglot', 'admin_notice' ) );
42
  }
43
  }
44
 
68
  return;
69
  }
70
 
71
+ $tab = $_GET[ 'tab' ]; //phpcs:ignore
72
+ $options = $_POST[ WEGLOT_SLUG ]; //phpcs:ignore
73
  $options_bdd = $this->option_services->get_options_bdd_v3();
74
  switch ( $tab ) {
75
  case Helper_Tabs_Admin_Weglot::SETTINGS:
 
76
  $has_first_settings = $this->option_services->get_has_first_settings();
77
  $options = $this->sanitize_options_settings( $options, $has_first_settings );
78
+ $response = $this->option_services->save_options_to_weglot( $options, $has_first_settings );
79
 
80
  if ( $response['success'] ) {
81
  delete_transient( 'weglot_cache_cdn' );
82
 
83
+ $api_key_private = $this->option_services->get_api_key_private();
84
 
85
  $option_v2 = $this->option_services->get_options_from_v2();
86
  if ( ! $api_key_private && $option_v2 ) {
108
  case Helper_Tabs_Admin_Weglot::SUPPORT:
109
  if ( array_key_exists( 'active_wc_reload', $options ) && $options['active_wc_reload'] === 'on' ) {
110
  $options_bdd['active_wc_reload'] = true;
111
+ } else {
 
112
  $options_bdd['active_wc_reload'] = false;
113
  }
114
 
115
  $this->option_services->set_options( $options_bdd );
116
  break;
117
  case Helper_Tabs_Admin_Weglot::CUSTOM_URLS:
118
+ if ( null === $options_bdd ) {
119
+ $options_bdd['custom_urls'] = array();
120
  }
121
 
122
  if ( array_key_exists( 'custom_urls', $options ) ) {
123
  $options_bdd['custom_urls'] = $options['custom_urls'];
124
+ } else {
125
+ $options_bdd['custom_urls'] = array();
 
126
  }
127
 
128
  $this->option_services->set_options( $options_bdd );
141
  * @return array
142
  */
143
  public function sanitize_options_settings( $options, $has_first_settings = false ) {
144
+ $user_info = $this->user_api_services->get_user_info( $options['api_key_private'] );
145
+ $plans = $this->user_api_services->get_plans();
146
 
147
  // Limit language
148
  if (
158
 
159
  $default_options = $this->option_services->get_options_default();
160
 
161
+ $options['custom_settings']['button_style']['is_dropdown'] = isset( $options['custom_settings']['button_style']['is_dropdown'] );
162
+ $options['custom_settings']['button_style']['with_flags'] = isset( $options['custom_settings']['button_style']['with_flags'] );
163
+ $options['custom_settings']['button_style']['full_name'] = isset( $options['custom_settings']['button_style']['full_name'] );
164
+ $options['custom_settings']['button_style']['with_name'] = isset( $options['custom_settings']['button_style']['with_name'] );
165
 
166
  if ( $has_first_settings ) {
167
  $options['custom_settings']['button_style']['is_dropdown'] = $default_options['custom_settings']['button_style']['is_dropdown'];
170
  $options['custom_settings']['button_style']['with_name'] = $default_options['custom_settings']['button_style']['with_name'];
171
  }
172
 
173
+ $options['custom_settings']['button_style']['custom_css'] = isset( $options['custom_settings']['button_style']['custom_css'] ) ? stripcslashes( $options['custom_settings']['button_style']['custom_css'] ) : '';
174
 
175
+ $options['custom_settings']['button_style']['flag_type'] = isset( $options['custom_settings']['button_style']['flag_type'] ) ? $options['custom_settings']['button_style']['flag_type'] : Helper_Flag_Type::RECTANGLE_MAT;
176
 
177
+ $options['custom_settings']['translate_email'] = isset( $options['custom_settings']['translate_email'] );
178
+ $options['custom_settings']['translate_search'] = isset( $options['custom_settings']['translate_search'] );
179
+ $options['custom_settings']['translate_amp'] = isset( $options['custom_settings']['translate_amp'] );
180
 
181
+ $options['auto_switch'] = isset( $options['auto_switch'] );
182
  foreach ( $options['languages'] as $key => $language ) {
183
  if ( 'active' === $key ) {
184
  continue;
186
  $options['languages'][ $key ]['enabled'] = ! isset( $options['languages'][ $key ]['enabled'] );
187
  }
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  if ( ! isset( $options['excluded_blocks'] ) ) {
190
+ $options['excluded_blocks'] = array();
191
+ } else {
192
+ array_walk_recursive(
193
+ $options['excluded_blocks'],
194
+ function ( &$element ) {
195
+ //We remove unwanted backslashes
196
+ $element = stripslashes( $element );
197
+ }
198
+ );
199
  }
 
 
 
 
 
200
 
201
  return $options;
202
  }
src/actions/admin/class-pages-weglot.php CHANGED
@@ -7,7 +7,6 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
-
11
  use WeglotWP\Helpers\Helper_Pages_Weglot;
12
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
13
 
@@ -38,8 +37,8 @@ class Pages_Weglot implements Hooks_Interface_Weglot {
38
  * @return void
39
  */
40
  public function hooks() {
41
- add_action( 'admin_menu', [ $this, 'weglot_plugin_menu' ] );
42
- add_action( 'admin_bar_menu', [ $this, 'add_admin_bar_menu' ], PHP_INT_MAX );
43
  }
44
 
45
  /**
@@ -114,7 +113,7 @@ class Pages_Weglot implements Hooks_Interface_Weglot {
114
 
115
  $menu_icon = 'data:image/svg+xml;base64,' . base64_encode( $weglot_logo_svg );
116
 
117
- add_menu_page( 'Weglot', 'Weglot', 'manage_options', Helper_Pages_Weglot::SETTINGS, [ $this, 'weglot_plugin_settings_page' ], $menu_icon );
118
  }
119
 
120
  /**
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
10
  use WeglotWP\Helpers\Helper_Pages_Weglot;
11
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
12
 
37
  * @return void
38
  */
39
  public function hooks() {
40
+ add_action( 'admin_menu', array( $this, 'weglot_plugin_menu' ) );
41
+ add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu' ), PHP_INT_MAX );
42
  }
43
 
44
  /**
113
 
114
  $menu_icon = 'data:image/svg+xml;base64,' . base64_encode( $weglot_logo_svg );
115
 
116
+ add_menu_page( 'Weglot', 'Weglot', 'manage_options', Helper_Pages_Weglot::SETTINGS, array( $this, 'weglot_plugin_settings_page' ), $menu_icon );
117
  }
118
 
119
  /**
src/actions/admin/class-plugin-links-weglot.php CHANGED
@@ -22,7 +22,7 @@ class Plugin_Links_Weglot implements Hooks_Interface_Weglot {
22
  * @return void
23
  */
24
  public function hooks() {
25
- add_filter( 'plugin_action_links_' . WEGLOT_BNAME, [ $this, 'weglot_plugin_action_links' ] );
26
  }
27
 
28
  /**
@@ -34,7 +34,7 @@ class Plugin_Links_Weglot implements Hooks_Interface_Weglot {
34
  * @return array
35
  */
36
  public function weglot_plugin_action_links( $links ) {
37
- $url = get_admin_url( null, sprintf( 'admin.php?page=%s', Helper_Pages_Weglot::SETTINGS ) );
38
  $text = __( 'Settings', 'weglot' );
39
 
40
  $links[] = sprintf( '<a href="%s">%s</a>', $url, $text );
22
  * @return void
23
  */
24
  public function hooks() {
25
+ add_filter( 'plugin_action_links_' . WEGLOT_BNAME, array( $this, 'weglot_plugin_action_links' ) );
26
  }
27
 
28
  /**
34
  * @return array
35
  */
36
  public function weglot_plugin_action_links( $links ) {
37
+ $url = get_admin_url( null, sprintf( 'admin.php?page=%s', Helper_Pages_Weglot::SETTINGS ) );
38
  $text = __( 'Settings', 'weglot' );
39
 
40
  $links[] = sprintf( '<a href="%s">%s</a>', $url, $text );
src/actions/class-email-translate-weglot.php CHANGED
@@ -9,7 +9,6 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
 
11
 
12
-
13
  /**
14
  * Translate Emails who use wp_mail
15
  *
@@ -34,7 +33,7 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
34
  * @return void
35
  */
36
  public function hooks() {
37
- add_filter( 'wp_mail', [ $this, 'weglot_translate_emails' ], 10, 1 );
38
  }
39
 
40
  /**
@@ -55,10 +54,10 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
55
  $current_and_original_language = weglot_get_current_and_original_language();
56
  $current_and_original_language_forced = apply_filters( 'weglot_translate_email_languages_forced', false );
57
 
58
- $message_and_subject = [
59
  'subject' => $args['subject'],
60
  'message' => $args['message'],
61
- ];
62
 
63
  $message_and_subject_translated = false;
64
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
 
11
 
 
12
  /**
13
  * Translate Emails who use wp_mail
14
  *
33
  * @return void
34
  */
35
  public function hooks() {
36
+ add_filter( 'wp_mail', array( $this, 'weglot_translate_emails' ), 10, 1 );
37
  }
38
 
39
  /**
54
  $current_and_original_language = weglot_get_current_and_original_language();
55
  $current_and_original_language_forced = apply_filters( 'weglot_translate_email_languages_forced', false );
56
 
57
+ $message_and_subject = array(
58
  'subject' => $args['subject'],
59
  'message' => $args['message'],
60
+ );
61
 
62
  $message_and_subject_translated = false;
63
 
src/actions/class-migration-weglot.php CHANGED
@@ -2,7 +2,9 @@
2
 
3
  namespace WeglotWP\Actions;
4
 
5
- defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
 
 
6
 
7
  use Morphism\Morphism;
8
  use WeglotWP\Models\Hooks_Interface_Weglot;
@@ -20,7 +22,7 @@ class Migration_Weglot implements Hooks_Interface_Weglot {
20
  * @since 2.0.0
21
  */
22
  public function __construct() {
23
- $this->migration_services = weglot_get_service( 'Migration_Service_Weglot' );
24
  }
25
 
26
 
2
 
3
  namespace WeglotWP\Actions;
4
 
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
 
9
  use Morphism\Morphism;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
22
  * @since 2.0.0
23
  */
24
  public function __construct() {
25
+ $this->migration_services = weglot_get_service( 'Migration_Service_Weglot' );
26
  }
27
 
28
 
src/actions/class-register-widget-weglot.php CHANGED
@@ -2,7 +2,9 @@
2
 
3
  namespace WeglotWP\Actions;
4
 
5
- defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
 
 
6
 
7
  use WeglotWP\Models\Hooks_Interface_Weglot;
8
 
@@ -18,7 +20,7 @@ class Register_Widget_Weglot implements Hooks_Interface_Weglot {
18
  * @return void
19
  */
20
  public function hooks() {
21
- add_action( 'widgets_init', [ $this, 'register_widget_weglot' ] );
22
  }
23
 
24
  /**
2
 
3
  namespace WeglotWP\Actions;
4
 
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
 
20
  * @return void
21
  */
22
  public function hooks() {
23
+ add_action( 'widgets_init', array( $this, 'register_widget_weglot' ) );
24
  }
25
 
26
  /**
src/actions/front/class-clean-options.php CHANGED
@@ -12,7 +12,7 @@ class Clean_Options implements Hooks_Interface_Weglot {
12
 
13
 
14
  public function __construct() {
15
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
16
  }
17
 
18
  /**
@@ -22,7 +22,7 @@ class Clean_Options implements Hooks_Interface_Weglot {
22
  * @return void
23
  */
24
  public function hooks() {
25
- add_action( 'init', [ $this, 'clean_options' ] );
26
  }
27
 
28
 
@@ -32,7 +32,7 @@ class Clean_Options implements Hooks_Interface_Weglot {
32
  * @return void
33
  */
34
  public function clean_options() {
35
- if( isset( $_GET['_weglot_clean_cache_cdn'] ) && 'true' === $_GET['_weglot_clean_cache_cdn'] ) {
36
  delete_transient( 'weglot_cache_cdn' );
37
  }
38
  }
12
 
13
 
14
  public function __construct() {
15
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
16
  }
17
 
18
  /**
22
  * @return void
23
  */
24
  public function hooks() {
25
+ add_action( 'init', array( $this, 'clean_options' ) );
26
  }
27
 
28
 
32
  * @return void
33
  */
34
  public function clean_options() {
35
+ if ( isset( $_GET['_weglot_clean_cache_cdn'] ) && 'true' === $_GET['_weglot_clean_cache_cdn'] ) {
36
  delete_transient( 'weglot_cache_cdn' );
37
  }
38
  }
src/actions/front/class-front-enqueue-weglot.php CHANGED
@@ -19,7 +19,7 @@ class Front_Enqueue_Weglot implements Hooks_Interface_Weglot {
19
  * @since 2.0
20
  */
21
  public function __construct() {
22
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
23
  }
24
 
25
  /**
@@ -29,8 +29,8 @@ class Front_Enqueue_Weglot implements Hooks_Interface_Weglot {
29
  * @return void
30
  */
31
  public function hooks() {
32
- add_action( 'wp_enqueue_scripts', [ $this, 'weglot_wp_enqueue_scripts' ] );
33
- add_action( 'login_enqueue_scripts', [ $this, 'weglot_wp_enqueue_scripts' ] );
34
  }
35
 
36
 
19
  * @since 2.0
20
  */
21
  public function __construct() {
22
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
23
  }
24
 
25
  /**
29
  * @return void
30
  */
31
  public function hooks() {
32
+ add_action( 'wp_enqueue_scripts', array( $this, 'weglot_wp_enqueue_scripts' ) );
33
+ add_action( 'login_enqueue_scripts', array( $this, 'weglot_wp_enqueue_scripts' ) );
34
  }
35
 
36
 
src/actions/front/class-front-menu-weglot.php CHANGED
@@ -20,11 +20,11 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
20
  * @since 2.4.0
21
  */
22
  public function __construct() {
23
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
24
- $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
25
- $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
26
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
27
- $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
28
  }
29
 
30
  /**
@@ -38,9 +38,9 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
38
  return;
39
  }
40
 
41
- add_filter( 'wp_get_nav_menu_items', [ $this, 'weglot_wp_get_nav_menu_items' ], 20 );
42
- add_filter( 'nav_menu_link_attributes', [ $this, 'add_nav_menu_link_attributes' ], 10, 2 );
43
- add_filter( 'wp_nav_menu_objects', [ $this, 'wp_nav_menu_objects' ] );
44
  }
45
 
46
  /**
@@ -77,45 +77,45 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
77
  return $items;
78
  }
79
 
80
- $new_items = [];
81
  $offset = 0;
82
 
83
  foreach ( $items as $key => $item ) {
84
  if ( strpos( $item->post_name, 'weglot-switcher' ) === false ) {
85
  $item->menu_order += $offset;
86
- $new_items[] = $item;
87
  continue;
88
  }
89
  $id = $item->ID;
90
  $i = 0;
91
 
92
- $classes = [ 'weglot-lang', 'menu-item-weglot' , 'weglot-language' ];
93
- $options = $this->option_services->get_option( 'menu_switcher' );
94
- $with_flags = $this->option_services->get_option_button( 'with_flags' );
95
- $dropdown = 0;
96
  if ( isset( $options[ 'menu-item-' . $id ] ) && isset( $options[ 'menu-item-' . $id ]['dropdown'] ) ) {
97
  $dropdown = $options[ 'menu-item-' . $id ]['dropdown'];
98
  }
99
- $hide_current = 0;
100
  if ( isset( $options[ 'menu-item-' . $id ] ) && isset( $options[ 'menu-item-' . $id ]['hide_current'] ) ) {
101
  $hide_current = $options[ 'menu-item-' . $id ]['hide_current'];
102
  }
103
 
104
  if ( ! $hide_current && $with_flags ) {
105
- $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
106
  }
107
 
108
- $languages = weglot_get_languages_configured();
109
  $current_language = $this->request_url_services->get_current_language_entry();
110
 
111
  if ( $dropdown ) {
112
  $title = __( 'Choose your language', 'weglot' );
113
  if ( ! $hide_current ) {
114
- $title = $this->button_services->get_name_with_language_entry( $current_language );
115
  }
116
  $item->title = apply_filters( 'weglot_menu_parent_menu_item_title', $title );
117
  $item->attr_title = $current_language->getLocalName();
118
- $item->classes = array_merge( [ 'weglot-parent-menu-item' ], $classes, [ $current_language->getIso639() ] );
119
  $new_items[] = $item;
120
  $offset++;
121
  }
@@ -131,9 +131,9 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
131
  continue;
132
  }
133
 
134
- $add_classes = [];
135
  if ( $hide_current && $with_flags ) { // Just for children without flag classes
136
- $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
137
  }
138
 
139
  $add_classes[] = 'weglot-' . $language->getIso639();
@@ -146,12 +146,12 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
146
  $language_item->title = $this->button_services->get_name_with_language_entry( $language );
147
  $language_item->attr_title = $language->getLocalName();
148
 
149
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
150
- $l = isset($language_code_rewrited[$language->getIso639()]) ? $language_code_rewrited[$language->getIso639()]:$language->getIso639();
151
- $language_item->url = $this->custom_url_services->get_link_button_with_key_code( $l );
152
 
153
- $language_item->lang = $language->getIso639();
154
- $language_item->classes = array_merge( $classes, $add_classes );
155
  $language_item->menu_order += $offset + $i++;
156
  if ( $dropdown ) {
157
  $language_item->menu_item_parent = $item->db_id;
@@ -186,7 +186,7 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
186
  * @return array
187
  */
188
  public function wp_nav_menu_objects( $items ) {
189
- $r_ids = $k_ids = [];
190
 
191
  foreach ( $items as $item ) {
192
  if ( ! empty( $item->classes ) && is_array( $item->classes ) ) {
@@ -232,7 +232,7 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
232
  * @return array
233
  */
234
  public function add_nav_menu_link_attributes( $attrs, $item ) {
235
- $str = 'weglot-switcher';
236
  if ( strpos( $item->post_name, $str ) !== false ) {
237
  $current_language = $this->request_url_services->get_current_language();
238
  if ( ! $this->request_url_services->is_translatable_url() || ! weglot_current_url_is_eligible() ) {
20
  * @since 2.4.0
21
  */
22
  public function __construct() {
23
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
24
+ $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
25
+ $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
26
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
27
+ $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
28
  }
29
 
30
  /**
38
  return;
39
  }
40
 
41
+ add_filter( 'wp_get_nav_menu_items', array( $this, 'weglot_wp_get_nav_menu_items' ), 20 );
42
+ add_filter( 'nav_menu_link_attributes', array( $this, 'add_nav_menu_link_attributes' ), 10, 2 );
43
+ add_filter( 'wp_nav_menu_objects', array( $this, 'wp_nav_menu_objects' ) );
44
  }
45
 
46
  /**
77
  return $items;
78
  }
79
 
80
+ $new_items = array();
81
  $offset = 0;
82
 
83
  foreach ( $items as $key => $item ) {
84
  if ( strpos( $item->post_name, 'weglot-switcher' ) === false ) {
85
  $item->menu_order += $offset;
86
+ $new_items[] = $item;
87
  continue;
88
  }
89
  $id = $item->ID;
90
  $i = 0;
91
 
92
+ $classes = array( 'weglot-lang', 'menu-item-weglot', 'weglot-language' );
93
+ $options = $this->option_services->get_option( 'menu_switcher' );
94
+ $with_flags = $this->option_services->get_option_button( 'with_flags' );
95
+ $dropdown = 0;
96
  if ( isset( $options[ 'menu-item-' . $id ] ) && isset( $options[ 'menu-item-' . $id ]['dropdown'] ) ) {
97
  $dropdown = $options[ 'menu-item-' . $id ]['dropdown'];
98
  }
99
+ $hide_current = 0;
100
  if ( isset( $options[ 'menu-item-' . $id ] ) && isset( $options[ 'menu-item-' . $id ]['hide_current'] ) ) {
101
  $hide_current = $options[ 'menu-item-' . $id ]['hide_current'];
102
  }
103
 
104
  if ( ! $hide_current && $with_flags ) {
105
+ $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
106
  }
107
 
108
+ $languages = weglot_get_current_languages_configured();
109
  $current_language = $this->request_url_services->get_current_language_entry();
110
 
111
  if ( $dropdown ) {
112
  $title = __( 'Choose your language', 'weglot' );
113
  if ( ! $hide_current ) {
114
+ $title = $this->button_services->get_name_with_language_entry( $current_language );
115
  }
116
  $item->title = apply_filters( 'weglot_menu_parent_menu_item_title', $title );
117
  $item->attr_title = $current_language->getLocalName();
118
+ $item->classes = array_merge( array( 'weglot-parent-menu-item' ), $classes, array( $current_language->getIso639() ) );
119
  $new_items[] = $item;
120
  $offset++;
121
  }
131
  continue;
132
  }
133
 
134
+ $add_classes = array();
135
  if ( $hide_current && $with_flags ) { // Just for children without flag classes
136
+ $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
137
  }
138
 
139
  $add_classes[] = 'weglot-' . $language->getIso639();
146
  $language_item->title = $this->button_services->get_name_with_language_entry( $language );
147
  $language_item->attr_title = $language->getLocalName();
148
 
149
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
150
+ $l = isset( $language_code_rewrited[ $language->getIso639() ] ) ? $language_code_rewrited[ $language->getIso639() ] : $language->getIso639();
151
+ $language_item->url = $this->custom_url_services->get_link_button_with_key_code( $l );
152
 
153
+ $language_item->lang = $language->getIso639();
154
+ $language_item->classes = array_merge( $classes, $add_classes );
155
  $language_item->menu_order += $offset + $i++;
156
  if ( $dropdown ) {
157
  $language_item->menu_item_parent = $item->db_id;
186
  * @return array
187
  */
188
  public function wp_nav_menu_objects( $items ) {
189
+ $r_ids = $k_ids = array();
190
 
191
  foreach ( $items as $item ) {
192
  if ( ! empty( $item->classes ) && is_array( $item->classes ) ) {
232
  * @return array
233
  */
234
  public function add_nav_menu_link_attributes( $attrs, $item ) {
235
+ $str = 'weglot-switcher';
236
  if ( strpos( $item->post_name, $str ) !== false ) {
237
  $current_language = $this->request_url_services->get_current_language();
238
  if ( ! $this->request_url_services->is_translatable_url() || ! weglot_current_url_is_eligible() ) {
src/actions/front/class-redirect-comment.php CHANGED
@@ -21,7 +21,7 @@ class Redirect_Comment implements Hooks_Interface_Weglot {
21
  * @return void
22
  */
23
  public function hooks() {
24
- add_filter( 'comment_post_redirect', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ] );
25
  }
26
  }
27
 
21
  * @return void
22
  */
23
  public function hooks() {
24
+ add_filter( 'comment_post_redirect', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
25
  }
26
  }
27
 
src/actions/front/class-redirect-log-user-weglot.php CHANGED
@@ -22,7 +22,7 @@ class Redirect_Log_User_Weglot implements Hooks_Interface_Weglot {
22
  */
23
  public function hooks() {
24
  // add_filter( 'login_redirect', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ] );
25
- add_filter( 'logout_redirect', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ] );
26
  }
27
  }
28
 
22
  */
23
  public function hooks() {
24
  // add_filter( 'login_redirect', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ] );
25
+ add_filter( 'logout_redirect', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ) );
26
  }
27
  }
28
 
src/actions/front/class-search-weglot.php CHANGED
@@ -21,8 +21,8 @@ class Search_Weglot implements Hooks_Interface_Weglot {
21
  * @since 2.4.0
22
  */
23
  public function __construct() {
24
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
- $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
26
  }
27
 
28
  /**
@@ -33,15 +33,15 @@ class Search_Weglot implements Hooks_Interface_Weglot {
33
  */
34
  public function hooks() {
35
 
36
- if( Helper_Is_Admin::is_wp_admin()) {
37
- return;
38
- }
39
 
40
  $search_active = $this->option_services->get_option( 'active_search' );
41
 
42
  if ( $search_active ) {
43
- add_action( 'pre_get_posts', [ $this, 'pre_get_posts_translate' ] );
44
- add_filter( 'get_search_query', [ $this, 'get_search_query_translate' ] );
45
  }
46
  }
47
 
@@ -67,12 +67,12 @@ class Search_Weglot implements Hooks_Interface_Weglot {
67
  }
68
 
69
  try {
70
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
71
- $toTranslateLanguageIso = ($key = array_search($current_language,$language_code_rewrited)) ? $key:$current_language;
72
 
73
  $parser = $this->parser_services->get_parser();
74
  $this->old_search = $query->query_vars['s'];
75
- $this->new_search = $parser->translate( $query->query_vars[ 's' ], $toTranslateLanguageIso, $original_language ); //phpcs:ignore
76
 
77
  if ( empty( $this->new_search ) ) {
78
  return;
@@ -90,6 +90,6 @@ class Search_Weglot implements Hooks_Interface_Weglot {
90
  * @return string
91
  */
92
  public function get_search_query_translate( $string ) {
93
- return ($this->old_search) ? $this->old_search : $string;
94
  }
95
  }
21
  * @since 2.4.0
22
  */
23
  public function __construct() {
24
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
+ $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
26
  }
27
 
28
  /**
33
  */
34
  public function hooks() {
35
 
36
+ if ( Helper_Is_Admin::is_wp_admin() ) {
37
+ return;
38
+ }
39
 
40
  $search_active = $this->option_services->get_option( 'active_search' );
41
 
42
  if ( $search_active ) {
43
+ add_action( 'pre_get_posts', array( $this, 'pre_get_posts_translate' ) );
44
+ add_filter( 'get_search_query', array( $this, 'get_search_query_translate' ) );
45
  }
46
  }
47
 
67
  }
68
 
69
  try {
70
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
71
+ $to_translate_language_iso = ( $key = array_search( $current_language, $language_code_rewrited ) ) ? $key : $current_language;
72
 
73
  $parser = $this->parser_services->get_parser();
74
  $this->old_search = $query->query_vars['s'];
75
+ $this->new_search = $parser->translate( $query->query_vars[ 's' ], $to_translate_language_iso, $original_language ); //phpcs:ignore
76
 
77
  if ( empty( $this->new_search ) ) {
78
  return;
90
  * @return string
91
  */
92
  public function get_search_query_translate( $string ) {
93
+ return ( $this->old_search ) ? $this->old_search : $string;
94
  }
95
  }
src/actions/front/class-shortcode-weglot.php CHANGED
@@ -21,7 +21,7 @@ class Shortcode_Weglot {
21
  $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
22
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
23
 
24
- add_shortcode( 'weglot_switcher', [ $this, 'weglot_switcher_callback' ] );
25
  }
26
 
27
  /**
21
  $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
22
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
23
 
24
+ add_shortcode( 'weglot_switcher', array( $this, 'weglot_switcher_callback' ) );
25
  }
26
 
27
  /**
src/actions/front/class-translate-page-weglot.php CHANGED
@@ -9,7 +9,6 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
  use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
12
-
13
  use Weglot\Client\Api\Enum\BotType;
14
  use Weglot\Util\Server;
15
 
@@ -25,12 +24,12 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
25
  * @since 2.0
26
  */
27
  public function __construct() {
28
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
29
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
30
- $this->redirect_services = weglot_get_service( 'Redirect_Service_Weglot' );
31
- $this->translate_services = weglot_get_service( 'Translate_Service_Weglot' );
32
- $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
33
- $this->href_lang_services = weglot_get_service( 'Href_Lang_Service_Weglot' );
34
  }
35
 
36
  /**
@@ -40,15 +39,15 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
40
  * @return void
41
  */
42
  public function hooks() {
43
- if( Helper_Is_Admin::is_wp_admin()) {
44
- return;
45
- }
46
 
47
  if ( is_admin() && ( ! wp_doing_ajax() || $this->no_translate_action_ajax() ) ) {
48
  return;
49
  }
50
 
51
- $this->api_key = $this->option_services->get_option( 'api_key' );
52
 
53
  if ( ! $this->api_key ) {
54
  return;
@@ -60,9 +59,9 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
60
  ) {
61
  return;
62
  }
63
- $this->request_url_services->init_weglot_url();
64
  $this->request_url_services->get_weglot_url()->detectUrlDetails();
65
- $this->current_language = $this->request_url_services->get_current_language();
66
 
67
  if ( $this->private_language_services->is_active_private_mode_for_lang( $this->current_language ) ) {
68
  return;
@@ -71,8 +70,8 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
71
  $this->prepare_request_uri();
72
  $this->prepare_rtl_language();
73
 
74
- add_action( 'init', [ $this, 'weglot_init' ], 11 );
75
- add_action( 'wp_head', [ $this, 'weglot_href_lang' ] );
76
  }
77
 
78
  /**
@@ -81,22 +80,25 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
81
  * @return boolean
82
  */
83
  protected function no_translate_action_ajax() {
84
- $action_ajax_no_translate = apply_filters( 'weglot_ajax_no_translate', [
85
- 'add-menu-item', // WP Core
86
- 'query-attachments', // WP Core
87
- 'avia_ajax_switch_menu_walker', // Enfold theme
88
- 'query-themes', // WP Core
89
- 'wpestate_ajax_check_booking_valability_internal', // WP Estate theme
90
- 'wpestate_ajax_add_booking', // WP Estate theme
91
- 'wpestate_ajax_check_booking_valability', // WP Estate theme
92
- 'mailster_get_template', // Mailster Pro,
93
- 'mmp_map_settings', // MMP Map,
94
- 'elementor_ajax', // Elementor since 2.5
95
- 'ct_get_svg_icon_sets', // Oxygen
96
- 'oxy_render_nav_menu', // Oxygen
97
- 'hotel_booking_ajax_add_to_cart', // Hotel booking plugin
98
- 'imagify_get_admin_bar_profile', // Imagify Admin Bar
99
- ] );
 
 
 
100
 
101
  if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && in_array( $_POST['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
102
  return true;
@@ -109,7 +111,6 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
109
  return false;
110
  }
111
 
112
-
113
  /**
114
  * @see init
115
  * @since 2.0
@@ -123,8 +124,8 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
123
  return;
124
  }
125
 
126
- $this->noredirect = false;
127
- $this->original_language = $this->option_services->get_option( 'original_language' );
128
  if ( empty( $this->original_language ) ) {
129
  return;
130
  }
@@ -171,8 +172,6 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
171
  }
172
  }
173
 
174
-
175
-
176
  /**
177
  * @since 2.0
178
  *
@@ -215,15 +214,23 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
215
  return;
216
  }
217
 
218
- $request_without_language = array_values(array_filter( explode( '/', str_replace(
219
- '/' . $current_language . '/',
220
- '/',
221
- strpos($_SERVER['REQUEST_URI'], "?") ? substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], "?")) : $_SERVER['REQUEST_URI']
222
- ) ), 'strlen' ));
 
 
 
 
 
 
 
 
223
 
224
  $index_entries = count( $request_without_language ) - 1;
225
  if ( isset( $request_without_language[ $index_entries ] ) ) {
226
- $slug_in_work = $request_without_language[ $index_entries ];
227
  }
228
 
229
  // Like is_home
@@ -235,32 +242,23 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
235
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
236
 
237
  // No language configured
238
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
239
- $toTranslateLanguageIso = ($key = array_search($current_language,$language_code_rewrited)) ? $key:$current_language;
240
-
241
- if ( ! isset( $custom_urls[ $toTranslateLanguageIso ] ) ) {
242
- $this->request_uri_default();
243
- return;
244
- }
245
 
246
- $key_slug = array_search( $slug_in_work, $custom_urls[ $toTranslateLanguageIso ] ); //phpcs:ignore
247
-
248
- // No custom URL for this language with this slug
249
- if ( ! isset( $custom_urls[ $toTranslateLanguageIso ][ $slug_in_work ] ) && false === $key_slug ) {
250
  $this->request_uri_default();
251
  return;
252
  }
253
 
254
- // Custom URL exist but not good slug
255
- if ( ! isset( $custom_urls[ $toTranslateLanguageIso ][ $slug_in_work ] ) ) {
256
- return;
257
- }
258
-
259
  $_SERVER['REQUEST_URI'] = str_replace(
260
  '/' . $current_language . '/',
261
  '/',
262
- str_replace( $slug_in_work, $custom_urls[ $toTranslateLanguageIso ][ $slug_in_work ], $_SERVER['REQUEST_URI'] ) //phpcs:ignore
263
  );
 
 
 
 
264
  }
265
 
266
  /**
@@ -286,5 +284,3 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
286
  echo $this->href_lang_services->generate_href_lang_tags(); //phpcs:ignore
287
  }
288
  }
289
-
290
-
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
  use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
 
12
  use Weglot\Client\Api\Enum\BotType;
13
  use Weglot\Util\Server;
14
 
24
  * @since 2.0
25
  */
26
  public function __construct() {
27
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
28
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
29
+ $this->redirect_services = weglot_get_service( 'Redirect_Service_Weglot' );
30
+ $this->translate_services = weglot_get_service( 'Translate_Service_Weglot' );
31
+ $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
32
+ $this->href_lang_services = weglot_get_service( 'Href_Lang_Service_Weglot' );
33
  }
34
 
35
  /**
39
  * @return void
40
  */
41
  public function hooks() {
42
+ if ( Helper_Is_Admin::is_wp_admin() ) {
43
+ return;
44
+ }
45
 
46
  if ( is_admin() && ( ! wp_doing_ajax() || $this->no_translate_action_ajax() ) ) {
47
  return;
48
  }
49
 
50
+ $this->api_key = $this->option_services->get_option( 'api_key' );
51
 
52
  if ( ! $this->api_key ) {
53
  return;
59
  ) {
60
  return;
61
  }
62
+ $this->request_url_services->init_weglot_url();
63
  $this->request_url_services->get_weglot_url()->detectUrlDetails();
64
+ $this->current_language = $this->request_url_services->get_current_language();
65
 
66
  if ( $this->private_language_services->is_active_private_mode_for_lang( $this->current_language ) ) {
67
  return;
70
  $this->prepare_request_uri();
71
  $this->prepare_rtl_language();
72
 
73
+ add_action( 'init', array( $this, 'weglot_init' ), 11 );
74
+ add_action( 'wp_head', array( $this, 'weglot_href_lang' ) );
75
  }
76
 
77
  /**
80
  * @return boolean
81
  */
82
  protected function no_translate_action_ajax() {
83
+ $action_ajax_no_translate = apply_filters(
84
+ 'weglot_ajax_no_translate',
85
+ array(
86
+ 'add-menu-item', // WP Core
87
+ 'query-attachments', // WP Core
88
+ 'avia_ajax_switch_menu_walker', // Enfold theme
89
+ 'query-themes', // WP Core
90
+ 'wpestate_ajax_check_booking_valability_internal', // WP Estate theme
91
+ 'wpestate_ajax_add_booking', // WP Estate theme
92
+ 'wpestate_ajax_check_booking_valability', // WP Estate theme
93
+ 'mailster_get_template', // Mailster Pro,
94
+ 'mmp_map_settings', // MMP Map,
95
+ 'elementor_ajax', // Elementor since 2.5
96
+ 'ct_get_svg_icon_sets', // Oxygen
97
+ 'oxy_render_nav_menu', // Oxygen
98
+ 'hotel_booking_ajax_add_to_cart', // Hotel booking plugin
99
+ 'imagify_get_admin_bar_profile', // Imagify Admin Bar
100
+ )
101
+ );
102
 
103
  if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && in_array( $_POST['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
104
  return true;
111
  return false;
112
  }
113
 
 
114
  /**
115
  * @see init
116
  * @since 2.0
124
  return;
125
  }
126
 
127
+ $this->noredirect = false;
128
+ $this->original_language = $this->option_services->get_option( 'original_language' );
129
  if ( empty( $this->original_language ) ) {
130
  return;
131
  }
172
  }
173
  }
174
 
 
 
175
  /**
176
  * @since 2.0
177
  *
214
  return;
215
  }
216
 
217
+ $request_without_language = array_values(
218
+ array_filter(
219
+ explode(
220
+ '/',
221
+ str_replace(
222
+ '/' . $current_language . '/',
223
+ '/',
224
+ strpos( $_SERVER['REQUEST_URI'], '?' ) ? substr( $_SERVER['REQUEST_URI'], 0, strpos( $_SERVER['REQUEST_URI'], '?' ) ) : $_SERVER['REQUEST_URI']
225
+ )
226
+ ),
227
+ 'strlen'
228
+ )
229
+ );
230
 
231
  $index_entries = count( $request_without_language ) - 1;
232
  if ( isset( $request_without_language[ $index_entries ] ) ) {
233
+ $slug_in_work = $request_without_language[ $index_entries ];
234
  }
235
 
236
  // Like is_home
242
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
243
 
244
  // No language configured
245
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
246
+ $to_translate_language_iso = ( $key = array_search( $current_language, $language_code_rewrited ) ) ? $key : $current_language;
 
 
 
 
 
247
 
248
+ if ( ! isset( $custom_urls[ $to_translate_language_iso ] ) ) {
 
 
 
249
  $this->request_uri_default();
250
  return;
251
  }
252
 
 
 
 
 
 
253
  $_SERVER['REQUEST_URI'] = str_replace(
254
  '/' . $current_language . '/',
255
  '/',
256
+ $_SERVER['REQUEST_URI']
257
  );
258
+
259
+ foreach ( $custom_urls[ $to_translate_language_iso ] as $key => $value ) {
260
+ $_SERVER['REQUEST_URI'] = str_replace( '/' . $key . '/', '/' . $value . '/', $_SERVER['REQUEST_URI'] );
261
+ }
262
  }
263
 
264
  /**
284
  echo $this->href_lang_services->generate_href_lang_tags(); //phpcs:ignore
285
  }
286
  }
 
 
src/class-bootstrap-weglot.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
 
 
11
  /**
12
  * Init plugin
13
  *
@@ -19,14 +20,14 @@ class Bootstrap_Weglot {
19
  * @since 2.0
20
  * @var array
21
  */
22
- protected $actions = [];
23
 
24
  /**
25
  * List class services
26
  * @since 2.0
27
  * @var array
28
  */
29
- protected $services = [];
30
 
31
  /**
32
  * Set actions
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
 
11
+
12
  /**
13
  * Init plugin
14
  *
20
  * @since 2.0
21
  * @var array
22
  */
23
+ protected $actions = array();
24
 
25
  /**
26
  * List class services
27
  * @since 2.0
28
  * @var array
29
  */
30
+ protected $services = array();
31
 
32
  /**
33
  * Set actions
src/domcheckers/class-button-data-value.php CHANGED
@@ -2,13 +2,14 @@
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
 
 
 
 
 
12
  /**
13
  * @since 2.0.6
14
  */
2
 
3
  namespace WeglotWP\Domcheckers;
4
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Dom\AbstractDomChecker;
10
+ use Weglot\Client\Api\Enum\WordType;
11
+
12
+
13
  /**
14
  * @since 2.0.6
15
  */
src/domcheckers/class-button-value.php CHANGED
@@ -2,13 +2,14 @@
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
 
 
 
 
 
12
  /**
13
  * @since 2.0.6
14
  */
2
 
3
  namespace WeglotWP\Domcheckers;
4
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Dom\AbstractDomChecker;
10
+ use Weglot\Client\Api\Enum\WordType;
11
+
12
+
13
  /**
14
  * @since 2.0.6
15
  */
src/domcheckers/class-input-reset.php CHANGED
@@ -2,12 +2,14 @@
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
  /**
12
  * @since 2.5.0
13
  */
2
 
3
  namespace WeglotWP\Domcheckers;
4
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
+
9
+ use Weglot\Parser\Check\Dom\AbstractDomChecker;
10
+ use Weglot\Client\Api\Enum\WordType;
11
+
12
+
13
  /**
14
  * @since 2.5.0
15
  */
src/domcheckers/class-link-data-href.php CHANGED
@@ -1,12 +1,13 @@
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}
1
  <?php
2
  namespace WeglotWP\Domcheckers;
3
 
 
 
4
  if ( ! defined( 'ABSPATH' ) ) {
5
  exit;
6
  }
7
 
8
+ use Weglot\Parser\Check\Dom\LinkHref;
9
+
10
+
11
  class Link_Data_Href extends LinkHref {
12
  /**
13
  * {@inheritdoc}
src/domcheckers/class-meta-facebook-image.php CHANGED
@@ -2,12 +2,14 @@
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
  /**
12
  * @since 2.5.0
13
  */
2
 
3
  namespace WeglotWP\Domcheckers;
4
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
+
9
+ use Weglot\Parser\Check\Dom\AbstractDomChecker;
10
+ use Weglot\Client\Api\Enum\WordType;
11
+
12
+
13
  /**
14
  * @since 2.5.0
15
  */
src/domcheckers/class-meta-twitter-image.php CHANGED
@@ -2,12 +2,14 @@
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
  /**
12
  * @since 2.5.0
13
  */
2
 
3
  namespace WeglotWP\Domcheckers;
4
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
+
9
+ use Weglot\Parser\Check\Dom\AbstractDomChecker;
10
+ use Weglot\Client\Api\Enum\WordType;
11
+
12
+
13
  /**
14
  * @since 2.5.0
15
  */
src/domcheckers/class-meta-twitter.php CHANGED
@@ -2,12 +2,14 @@
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
  /**
12
  * @since 2.0
13
  */
2
 
3
  namespace WeglotWP\Domcheckers;
4
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
+
9
+ use Weglot\Parser\Check\Dom\AbstractDomChecker;
10
+ use Weglot\Client\Api\Enum\WordType;
11
+
12
+
13
  /**
14
  * @since 2.0
15
  */
src/domcheckers/class-video-source.php CHANGED
@@ -2,12 +2,14 @@
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}
2
 
3
  namespace WeglotWP\Domcheckers;
4
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
+
9
+ use Weglot\Parser\Check\Dom\AbstractDomChecker;
10
+ use Weglot\Client\Api\Enum\WordType;
11
+
12
+
13
  class Video_Source extends AbstractDomChecker {
14
  /**
15
  * {@inheritdoc}
src/domlisteners/class-meta-listener-weglot.php CHANGED
@@ -2,32 +2,33 @@
2
 
3
  namespace WeglotWP\Domlisteners;
4
 
 
 
 
 
5
  use Weglot\Parser\Listener\AbstractCrawlerAfterListener;
6
  use Weglot\Parser\Parser;
7
  use Weglot\Client\Api\Enum\WordType;
8
 
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
 
13
  /**
14
  * @since 2.0
15
  */
16
  final class Meta_Listener_Weglot extends AbstractCrawlerAfterListener {
17
- protected $attributes = [
18
- 'name' => [
19
  'twitter:image',
20
  'twitter:card',
21
  'twitter:site',
22
  'twitter:creator',
23
- ],
24
- ];
25
 
26
  /**
27
  * {@inheritdoc}
28
  */
29
  protected function xpath() {
30
- $selectors = [];
31
  foreach ( $this->attributes as $name => $values ) {
32
  foreach ( $values as $value ) {
33
  $selectors[] = '@' . $name . ' = \'' . $value . '\'';
2
 
3
  namespace WeglotWP\Domlisteners;
4
 
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
  use Weglot\Parser\Listener\AbstractCrawlerAfterListener;
10
  use Weglot\Parser\Parser;
11
  use Weglot\Client\Api\Enum\WordType;
12
 
 
 
 
13
 
14
  /**
15
  * @since 2.0
16
  */
17
  final class Meta_Listener_Weglot extends AbstractCrawlerAfterListener {
18
+ protected $attributes = array(
19
+ 'name' => array(
20
  'twitter:image',
21
  'twitter:card',
22
  'twitter:site',
23
  'twitter:creator',
24
+ ),
25
+ );
26
 
27
  /**
28
  * {@inheritdoc}
29
  */
30
  protected function xpath() {
31
+ $selectors = array();
32
  foreach ( $this->attributes as $name => $values ) {
33
  foreach ( $values as $value ) {
34
  $selectors[] = '@' . $name . ' = \'' . $value . '\'';
src/helpers/class-helper-api.php CHANGED
@@ -6,17 +6,16 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * @since 3.0.0
11
  */
12
  abstract class Helper_API {
13
- const API_BASE = 'https://api.weglot.com';
14
-
15
- const API_BASE_STAGING = 'https://api-staging.weglot.com';
16
 
 
 
17
  const API_BASE_OLD = 'https://weglot.com/api/';
18
-
19
- const CDN_BASE = 'https://cdn.weglot.com/projects-settings/';
20
 
21
  /**
22
  * @since 3.0.0
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * @since 3.0.0
12
  */
13
  abstract class Helper_API {
 
 
 
14
 
15
+ const API_BASE = 'https://api.weglot.com';
16
+ const API_BASE_STAGING = 'https://api.weglot.dev';
17
  const API_BASE_OLD = 'https://weglot.com/api/';
18
+ const CDN_BASE = 'https://cdn.weglot.com/projects-settings/';
 
19
 
20
  /**
21
  * @since 3.0.0
src/helpers/class-helper-excluded-type.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use Weglot\Util\Regex\RegexEnum;
10
 
 
11
  /**
12
  * @since 3.0.0
13
  */
@@ -17,13 +18,13 @@ class Helper_Excluded_Type {
17
  * @return array
18
  */
19
  public static function get_excluded_type() {
20
- return [
21
  RegexEnum::START_WITH,
22
  RegexEnum::END_WITH,
23
  RegexEnum::CONTAIN,
24
  RegexEnum::IS_EXACTLY,
25
  RegexEnum::MATCH_REGEX,
26
- ];
27
  }
28
 
29
  /**
8
 
9
  use Weglot\Util\Regex\RegexEnum;
10
 
11
+
12
  /**
13
  * @since 3.0.0
14
  */
18
  * @return array
19
  */
20
  public static function get_excluded_type() {
21
+ return array(
22
  RegexEnum::START_WITH,
23
  RegexEnum::END_WITH,
24
  RegexEnum::CONTAIN,
25
  RegexEnum::IS_EXACTLY,
26
  RegexEnum::MATCH_REGEX,
27
+ );
28
  }
29
 
30
  /**
src/helpers/class-helper-filter-url-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * Function helper for URL replace filter
11
  *
@@ -19,7 +20,7 @@ abstract class Helper_Filter_Url_Weglot {
19
  * @return string
20
  */
21
  protected static function prevent_subfolder_install( $url ) {
22
- $current_and_original_language = weglot_get_current_and_original_language();
23
 
24
  $url_translate = $url->getForLanguage( $current_and_original_language['current'] );
25
  $double_language = sprintf( '/%s/%s/', $current_and_original_language['current'], $current_and_original_language['current'] );
@@ -50,8 +51,8 @@ abstract class Helper_Filter_Url_Weglot {
50
  * @return string
51
  */
52
  public static function filter_url_lambda( $url ) {
53
- $current_and_original_language = weglot_get_current_and_original_language();
54
- $request_url_service = weglot_get_request_url_service();
55
 
56
  if ( $current_and_original_language['current'] === $current_and_original_language['original'] ) {
57
  return $url;
@@ -70,18 +71,18 @@ abstract class Helper_Filter_Url_Weglot {
70
  * @return string
71
  */
72
  public static function filter_url_log_redirect( $url_filter ) {
73
- $current_and_original_language = weglot_get_current_and_original_language();
74
- $request_url_service = weglot_get_request_url_service();
75
- $choose_current_language = $current_and_original_language['current'];
76
 
77
  $url_filter = self::get_clean_base_url( $url_filter );
78
 
79
- $url = $request_url_service->create_url_object( $url_filter );
80
 
81
  if ( $current_and_original_language['current'] === $current_and_original_language['original']
82
  && isset( $_SERVER['HTTP_REFERER'] ) //phpcs:ignore
83
  ) {
84
- $url = $request_url_service->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
85
  $choose_current_language = $url->detectCurrentLanguage();
86
 
87
  if ( $choose_current_language !== $current_and_original_language['original'] ) {
@@ -128,7 +129,7 @@ abstract class Helper_Filter_Url_Weglot {
128
  } else {
129
  if ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
130
  // Ajax
131
- $url = $request_url_service->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
132
  $choose_current_language = $url->detectCurrentLanguage();
133
  $url = $request_url_service->create_url_object( $url_filter );
134
  }
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * Function helper for URL replace filter
12
  *
20
  * @return string
21
  */
22
  protected static function prevent_subfolder_install( $url ) {
23
+ $current_and_original_language = weglot_get_current_and_original_language();
24
 
25
  $url_translate = $url->getForLanguage( $current_and_original_language['current'] );
26
  $double_language = sprintf( '/%s/%s/', $current_and_original_language['current'], $current_and_original_language['current'] );
51
  * @return string
52
  */
53
  public static function filter_url_lambda( $url ) {
54
+ $current_and_original_language = weglot_get_current_and_original_language();
55
+ $request_url_service = weglot_get_request_url_service();
56
 
57
  if ( $current_and_original_language['current'] === $current_and_original_language['original'] ) {
58
  return $url;
71
  * @return string
72
  */
73
  public static function filter_url_log_redirect( $url_filter ) {
74
+ $current_and_original_language = weglot_get_current_and_original_language();
75
+ $request_url_service = weglot_get_request_url_service();
76
+ $choose_current_language = $current_and_original_language['current'];
77
 
78
  $url_filter = self::get_clean_base_url( $url_filter );
79
 
80
+ $url = $request_url_service->create_url_object( $url_filter );
81
 
82
  if ( $current_and_original_language['current'] === $current_and_original_language['original']
83
  && isset( $_SERVER['HTTP_REFERER'] ) //phpcs:ignore
84
  ) {
85
+ $url = $request_url_service->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
86
  $choose_current_language = $url->detectCurrentLanguage();
87
 
88
  if ( $choose_current_language !== $current_and_original_language['original'] ) {
129
  } else {
130
  if ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
131
  // Ajax
132
+ $url = $request_url_service->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
133
  $choose_current_language = $url->detectCurrentLanguage();
134
  $url = $request_url_service->create_url_object( $url_filter );
135
  }
src/helpers/class-helper-flag-type.php CHANGED
@@ -2,11 +2,11 @@
2
 
3
  namespace WeglotWP\Helpers;
4
 
5
- // Exit if accessed directly.
6
  if ( ! defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
9
 
 
10
  /**
11
  * @since 3.0.0
12
  */
2
 
3
  namespace WeglotWP\Helpers;
4
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * @since 3.0.0
12
  */
src/helpers/class-helper-is-admin.php CHANGED
@@ -2,11 +2,11 @@
2
 
3
  namespace WeglotWP\Helpers;
4
 
5
- // Exit if accessed directly.
6
  if ( ! defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
9
 
 
10
  /**
11
  * @since 3.1.1
12
  */
@@ -18,7 +18,6 @@ abstract class Helper_Is_Admin {
18
  */
19
  public static function is_wp_admin() {
20
 
21
- return is_admin() &&
22
- (!wp_doing_ajax() || (wp_doing_ajax() && isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'wp-admin') !== false));
23
  }
24
- }
2
 
3
  namespace WeglotWP\Helpers;
4
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * @since 3.1.1
12
  */
18
  */
19
  public static function is_wp_admin() {
20
 
21
+ return is_admin() && ( ! wp_doing_ajax() || ( wp_doing_ajax() && isset( $_SERVER['HTTP_REFERER'] ) && strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) !== false ) );
 
22
  }
23
+ }
src/helpers/class-helper-json-inline-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  *
11
  * @since 2.0
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  *
12
  * @since 2.0
src/helpers/class-helper-menu-options-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * @since 2.4.0
11
  */
@@ -27,16 +28,19 @@ abstract class Helper_Menu_Options_Weglot {
27
  * @return array
28
  */
29
  public static function get_menu_switcher_list_options() {
30
- return apply_filters( 'weglot_menu_switcher_options', [
31
- [
32
- 'key' => self::HIDE_CURRENT,
33
- 'title' => __( 'Hide the current language', 'weglot' ),
34
- ],
35
- [
36
- 'key' => self::DROPDOWN,
37
- 'title' => __( "Show as dropdown (By default it's a list)", 'weglot' ),
38
- ],
39
- ]);
 
 
 
40
  }
41
 
42
  /**
@@ -45,9 +49,12 @@ abstract class Helper_Menu_Options_Weglot {
45
  * @return array
46
  */
47
  public static function get_keys() {
48
- return apply_filters( 'weglot_menu_switcher_options_keys', [
49
- self::HIDE_CURRENT,
50
- self::DROPDOWN,
51
- ]);
 
 
 
52
  }
53
  }
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * @since 2.4.0
12
  */
28
  * @return array
29
  */
30
  public static function get_menu_switcher_list_options() {
31
+ return apply_filters(
32
+ 'weglot_menu_switcher_options',
33
+ array(
34
+ array(
35
+ 'key' => self::HIDE_CURRENT,
36
+ 'title' => __( 'Hide the current language', 'weglot' ),
37
+ ),
38
+ array(
39
+ 'key' => self::DROPDOWN,
40
+ 'title' => __( "Show as dropdown (By default it's a list)", 'weglot' ),
41
+ ),
42
+ )
43
+ );
44
  }
45
 
46
  /**
49
  * @return array
50
  */
51
  public static function get_keys() {
52
+ return apply_filters(
53
+ 'weglot_menu_switcher_options_keys',
54
+ array(
55
+ self::HIDE_CURRENT,
56
+ self::DROPDOWN,
57
+ )
58
+ );
59
  }
60
  }
src/helpers/class-helper-pages-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * Name pages
11
  *
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * Name pages
12
  *
src/helpers/class-helper-post-meta-weglot.php CHANGED
@@ -7,6 +7,7 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
9
 
 
10
  /**
11
  * @since 2.1.0
12
  */
7
  exit;
8
  }
9
 
10
+
11
  /**
12
  * @since 2.1.0
13
  */
src/helpers/class-helper-replace-url-weglot.php CHANGED
@@ -7,6 +7,7 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
9
 
 
10
  /**
11
  * @since 2.3.0
12
  */
@@ -17,7 +18,7 @@ class Helper_Replace_Url_Weglot {
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\>]+?)(\"|\')([^\>]+?)?>/',
@@ -26,7 +27,7 @@ class Helper_Replace_Url_Weglot {
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
  }
7
  exit;
8
  }
9
 
10
+
11
  /**
12
  * @since 2.3.0
13
  */
18
  * @return array
19
  */
20
  public static function get_replace_modify_link() {
21
+ $data = array(
22
  'a' => '/<a([^\>]+?)?href=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
23
  'datalink' => '/<([^\>]+?)?data-link=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
24
  'dataurl' => '/<([^\>]+?)?data-url=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
27
  'canonical' => '/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/',
28
  'amp' => '/<link rel="amphtml"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/',
29
  'meta' => '/<meta property="og:url"(.*?)?content=(\"|\')([^\s\>]+?)(\"|\')/',
30
+ );
31
 
32
  return apply_filters( 'weglot_get_replace_modify_link', $data );
33
  }
src/helpers/class-helper-rollback-weglot.php CHANGED
@@ -12,12 +12,13 @@ if ( ! defined( 'ABSPATH' ) ) {
12
  exit;
13
  }
14
 
 
15
  class Helper_Rollback_Weglot extends \Plugin_Upgrader {
16
 
17
  /**
18
  * Plugin rollback.
19
  *
20
- * @param $plugin
21
  * @param array $args
22
  *
23
  * @return array|bool|\WP_Error
@@ -51,17 +52,19 @@ class Helper_Rollback_Weglot extends \Plugin_Upgrader {
51
  add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
52
  add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
53
 
54
- $this->run( array(
55
- 'package' => $url,
56
- 'destination' => WP_PLUGIN_DIR,
57
- 'clear_destination' => true,
58
- 'clear_working' => true,
59
- 'hook_extra' => array(
60
- 'plugin' => $plugin,
61
- 'type' => 'plugin',
62
- 'action' => 'update',
63
- ),
64
- ) );
 
 
65
 
66
  // Cleanup our hooks, in case something else does a upgrade on this connection.
67
  remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
12
  exit;
13
  }
14
 
15
+
16
  class Helper_Rollback_Weglot extends \Plugin_Upgrader {
17
 
18
  /**
19
  * Plugin rollback.
20
  *
21
+ * @param $plugin
22
  * @param array $args
23
  *
24
  * @return array|bool|\WP_Error
52
  add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
53
  add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
54
 
55
+ $this->run(
56
+ array(
57
+ 'package' => $url,
58
+ 'destination' => WP_PLUGIN_DIR,
59
+ 'clear_destination' => true,
60
+ 'clear_working' => true,
61
+ 'hook_extra' => array(
62
+ 'plugin' => $plugin,
63
+ 'type' => 'plugin',
64
+ 'action' => 'update',
65
+ ),
66
+ )
67
+ );
68
 
69
  // Cleanup our hooks, in case something else does a upgrade on this connection.
70
  remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
src/helpers/class-helper-tabs-admin-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * Name pages
11
  *
@@ -42,12 +43,12 @@ abstract class Helper_Tabs_Admin_Weglot {
42
  * @return array
43
  */
44
  public static function get_tabs() {
45
- return [
46
  self::SETTINGS,
47
  self::STATUS,
48
  self::CUSTOM_URLS,
49
- self::SUPPORT
50
- ];
51
  }
52
 
53
  /**
@@ -58,19 +59,19 @@ abstract class Helper_Tabs_Admin_Weglot {
58
  * @return array
59
  */
60
  public static function get_full_tabs() {
61
- return [
62
- self::SETTINGS => [
63
  'title' => __( 'Settings', 'weglot' ),
64
  'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::SETTINGS ) ),
65
- ],
66
- self::STATUS => [
67
  'title' => __( 'Status', 'weglot' ),
68
  'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::STATUS ) ),
69
- ],
70
- self::CUSTOM_URLS => [
71
  'title' => __( 'Custom URLs', 'weglot' ),
72
  'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::CUSTOM_URLS ) ),
73
- ],
74
- ];
75
  }
76
  }
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * Name pages
12
  *
43
  * @return array
44
  */
45
  public static function get_tabs() {
46
+ return array(
47
  self::SETTINGS,
48
  self::STATUS,
49
  self::CUSTOM_URLS,
50
+ self::SUPPORT,
51
+ );
52
  }
53
 
54
  /**
59
  * @return array
60
  */
61
  public static function get_full_tabs() {
62
+ return array(
63
+ self::SETTINGS => array(
64
  'title' => __( 'Settings', 'weglot' ),
65
  'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::SETTINGS ) ),
66
+ ),
67
+ self::STATUS => array(
68
  'title' => __( 'Status', 'weglot' ),
69
  'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::STATUS ) ),
70
+ ),
71
+ self::CUSTOM_URLS => array(
72
  'title' => __( 'Custom URLs', 'weglot' ),
73
  'url' => get_admin_url( null, sprintf( 'admin.php?page=%s&tab=%s', Helper_Pages_Weglot::SETTINGS, self::CUSTOM_URLS ) ),
74
+ ),
75
+ );
76
  }
77
  }
src/models/class-abstract-notices-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * Abstract class for manage admin notices
11
  *
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * Abstract class for manage admin notices
12
  *
src/models/class-hooks-interface-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * Hooks interface
11
  *
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * Hooks interface
12
  *
src/models/class-schema-option-migration-v3.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Excluded_Type;
10
  use WeglotWP\Helpers\Helper_Flag_Type;
11
 
 
12
  class Schema_Option_Migration_V3 {
13
 
14
 
@@ -17,71 +18,71 @@ class Schema_Option_Migration_V3 {
17
  * @return array
18
  */
19
  public static function get_schema_migration_options_v3() {
20
- $schema = [
21
- 'api_key_private' => 'api_key',
22
- 'allowed' => 'allowed',
23
- 'language_from' => 'original_language',
24
- 'languages' => function( $options ) {
25
- $destinations = [];
26
  foreach ( $options['destination_language'] as $item ) {
27
- $destinations[] = [
28
  'language_to' => $item,
29
  'enabled' => isset( $options['private_mode'][ $item ] ) && ! $options['private_mode'][ $item ],
30
  'automatic_translation_enabled' => true,
31
- ];
32
  }
33
 
34
  return $destinations;
35
  },
36
- 'excluded_blocks' => (object) [
37
  'path' => 'exclude_blocks',
38
  'fn' => function( $blocks ) {
39
- $objects = [];
40
  foreach ( $blocks as $item ) {
41
- $objects[] = [
42
  'value' => $item,
43
- ];
44
  }
45
  return $objects;
46
  },
47
- ],
48
- 'excluded_paths' => (object) [
49
  'path' => 'exclude_urls',
50
  'fn' => function( $urls ) {
51
- $objects = [];
52
  foreach ( $urls as $item ) {
53
- $objects[] = [
54
  'type' => Helper_Excluded_Type::MATCH_REGEX,
55
  'value' => $item,
56
- ];
57
  }
58
  return $objects;
59
  },
60
- ],
61
- 'auto_switch' => (object) [
62
  'path' => 'auto_redirect',
63
  'fn' => function( $auto_redirect ) {
64
  return (bool) $auto_redirect;
65
  },
66
- ],
67
  'auto_switch_fallback' => 'original_language',
68
  'custom_settings' => function( $options ) {
69
- return [
70
  'translate_email' => (bool) $options['email_translate'],
71
  'translate_amp' => (bool) $options['translate_amp'],
72
  'translate_search' => (bool) $options['active_search'],
73
- 'button_style' => [
74
  'is_dropdown' => (bool) $options['is_dropdown'],
75
  'full_name' => (bool) $options['is_fullname'],
76
  'with_name' => (bool) $options['with_name'],
77
  'with_flags' => (bool) $options['with_flags'],
78
  'flag_type' => Helper_Flag_Type::get_flag_type_with_number( $options['flag_type'] ),
79
  'custom_css' => $options['override_css'],
80
- ],
81
- ];
82
  },
83
 
84
- ];
85
 
86
  return $schema;
87
  }
9
  use WeglotWP\Helpers\Helper_Excluded_Type;
10
  use WeglotWP\Helpers\Helper_Flag_Type;
11
 
12
+
13
  class Schema_Option_Migration_V3 {
14
 
15
 
18
  * @return array
19
  */
20
  public static function get_schema_migration_options_v3() {
21
+ $schema = array(
22
+ 'api_key_private' => 'api_key',
23
+ 'allowed' => 'allowed',
24
+ 'language_from' => 'original_language',
25
+ 'languages' => function( $options ) {
26
+ $destinations = array();
27
  foreach ( $options['destination_language'] as $item ) {
28
+ $destinations[] = array(
29
  'language_to' => $item,
30
  'enabled' => isset( $options['private_mode'][ $item ] ) && ! $options['private_mode'][ $item ],
31
  'automatic_translation_enabled' => true,
32
+ );
33
  }
34
 
35
  return $destinations;
36
  },
37
+ 'excluded_blocks' => (object) array(
38
  'path' => 'exclude_blocks',
39
  'fn' => function( $blocks ) {
40
+ $objects = array();
41
  foreach ( $blocks as $item ) {
42
+ $objects[] = array(
43
  'value' => $item,
44
+ );
45
  }
46
  return $objects;
47
  },
48
+ ),
49
+ 'excluded_paths' => (object) array(
50
  'path' => 'exclude_urls',
51
  'fn' => function( $urls ) {
52
+ $objects = array();
53
  foreach ( $urls as $item ) {
54
+ $objects[] = array(
55
  'type' => Helper_Excluded_Type::MATCH_REGEX,
56
  'value' => $item,
57
+ );
58
  }
59
  return $objects;
60
  },
61
+ ),
62
+ 'auto_switch' => (object) array(
63
  'path' => 'auto_redirect',
64
  'fn' => function( $auto_redirect ) {
65
  return (bool) $auto_redirect;
66
  },
67
+ ),
68
  'auto_switch_fallback' => 'original_language',
69
  'custom_settings' => function( $options ) {
70
+ return array(
71
  'translate_email' => (bool) $options['email_translate'],
72
  'translate_amp' => (bool) $options['translate_amp'],
73
  'translate_search' => (bool) $options['active_search'],
74
+ 'button_style' => array(
75
  'is_dropdown' => (bool) $options['is_dropdown'],
76
  'full_name' => (bool) $options['is_fullname'],
77
  'with_name' => (bool) $options['with_name'],
78
  'with_flags' => (bool) $options['with_flags'],
79
  'flag_type' => Helper_Flag_Type::get_flag_type_with_number( $options['flag_type'] ),
80
  'custom_css' => $options['override_css'],
81
+ ),
82
+ );
83
  },
84
 
85
+ );
86
 
87
  return $schema;
88
  }
src/models/class-schema-option-v3.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Helpers\Helper_Flag_Type;
10
 
 
11
  class Schema_Option_V3 {
12
 
13
  /**
@@ -15,17 +16,17 @@ class Schema_Option_V3 {
15
  * @return array
16
  */
17
  public static function get_schema_options_v3_compatible() {
18
- $schema = [
19
- 'api_key' => 'api_key',
20
- 'api_key_private' => 'api_key_private',
21
- 'allowed' => 'allowed',
22
- 'original_language' => 'language_from',
23
- 'translation_engine' => 'translation_engine',
24
- 'destination_language' => (object) [
25
  'path' => 'languages',
26
  'fn' => function( $languages ) {
27
- $destinations = [];
28
- if( !$languages ){
29
  return $destinations;
30
  }
31
  foreach ( $languages as $item ) {
@@ -34,18 +35,18 @@ class Schema_Option_V3 {
34
 
35
  return $destinations;
36
  },
37
- ],
38
- 'private_mode' => (object) [
39
  'path' => 'languages',
40
  'fn' => function( $languages ) {
41
- $private = [ 'active' => false ];
42
- if( !$languages ){
43
  return $private;
44
  }
45
  foreach ( $languages as $item ) {
46
  if ( ! $item['enabled'] ) {
47
  $private[ $item['language_to'] ] = true;
48
- $private['active'] = true;
49
  } else {
50
  $private[ $item['language_to'] ] = false;
51
  }
@@ -53,15 +54,15 @@ class Schema_Option_V3 {
53
 
54
  return $private;
55
  },
56
- ],
57
- 'auto_redirect' => 'auto_switch',
58
- 'autoswitch_fallback' => 'auto_switch_fallback',
59
- 'exclude_urls' => 'excluded_paths',
60
- 'exclude_blocks' => (object) [
61
  'path' => 'excluded_blocks',
62
  'fn' => function( $excluded_blocks ) {
63
- $excluded = [];
64
- if( !$excluded_blocks ){
65
  return $excluded;
66
  }
67
  foreach ( $excluded_blocks as $item ) {
@@ -69,13 +70,13 @@ class Schema_Option_V3 {
69
  }
70
  return $excluded;
71
  },
72
- ],
73
- 'custom_settings' => 'custom_settings',
74
- 'is_dropdown' => 'custom_settings.button_style.is_dropdown',
75
- 'is_fullname' => 'custom_settings.button_style.full_name',
76
- 'with_name' => 'custom_settings.button_style.with_name',
77
- 'with_flags' => 'custom_settings.button_style.with_flags',
78
- 'type_flags' => (object) [
79
  'path' => 'custom_settings.button_style.flag_type',
80
  'fn' => function( $flag_type ) {
81
  if ( $flag_type ) {
@@ -84,27 +85,27 @@ class Schema_Option_V3 {
84
 
85
  return Helper_Flag_Type::RECTANGLE_MAT;
86
  },
87
- ],
88
  'override_css' => 'custom_settings.button_style.custom_css',
89
  'email_translate' => 'custom_settings.translate_email',
90
  'active_search' => 'custom_settings.translate_search',
91
  'translate_amp' => 'custom_settings.translate_amp',
92
  'has_first_settings' => 'has_first_settings',
93
  'show_box_first_settings' => 'show_box_first_settings',
94
- 'custom_urls' => (object) [
95
  'path' => 'custom_urls',
96
  'fn' => function( $custom_urls ) {
97
  if ( $custom_urls ) {
98
  return $custom_urls;
99
  }
100
 
101
- return [];
102
  },
103
- ],
104
  'flag_css' => 'flag_css',
105
  'menu_switcher' => 'menu_switcher',
106
  'active_wc_reload' => 'active_wc_reload',
107
- ];
108
 
109
  return $schema;
110
  }
8
 
9
  use WeglotWP\Helpers\Helper_Flag_Type;
10
 
11
+
12
  class Schema_Option_V3 {
13
 
14
  /**
16
  * @return array
17
  */
18
  public static function get_schema_options_v3_compatible() {
19
+ $schema = array(
20
+ 'api_key' => 'api_key',
21
+ 'api_key_private' => 'api_key_private',
22
+ 'allowed' => 'allowed',
23
+ 'original_language' => 'language_from',
24
+ 'translation_engine' => 'translation_engine',
25
+ 'destination_language' => (object) array(
26
  'path' => 'languages',
27
  'fn' => function( $languages ) {
28
+ $destinations = array();
29
+ if ( ! $languages ) {
30
  return $destinations;
31
  }
32
  foreach ( $languages as $item ) {
35
 
36
  return $destinations;
37
  },
38
+ ),
39
+ 'private_mode' => (object) array(
40
  'path' => 'languages',
41
  'fn' => function( $languages ) {
42
+ $private = array( 'active' => false );
43
+ if ( ! $languages ) {
44
  return $private;
45
  }
46
  foreach ( $languages as $item ) {
47
  if ( ! $item['enabled'] ) {
48
  $private[ $item['language_to'] ] = true;
49
+ $private['active'] = true;
50
  } else {
51
  $private[ $item['language_to'] ] = false;
52
  }
54
 
55
  return $private;
56
  },
57
+ ),
58
+ 'auto_redirect' => 'auto_switch',
59
+ 'autoswitch_fallback' => 'auto_switch_fallback',
60
+ 'exclude_urls' => 'excluded_paths',
61
+ 'exclude_blocks' => (object) array(
62
  'path' => 'excluded_blocks',
63
  'fn' => function( $excluded_blocks ) {
64
+ $excluded = array();
65
+ if ( ! $excluded_blocks ) {
66
  return $excluded;
67
  }
68
  foreach ( $excluded_blocks as $item ) {
70
  }
71
  return $excluded;
72
  },
73
+ ),
74
+ 'custom_settings' => 'custom_settings',
75
+ 'is_dropdown' => 'custom_settings.button_style.is_dropdown',
76
+ 'is_fullname' => 'custom_settings.button_style.full_name',
77
+ 'with_name' => 'custom_settings.button_style.with_name',
78
+ 'with_flags' => 'custom_settings.button_style.with_flags',
79
+ 'type_flags' => (object) array(
80
  'path' => 'custom_settings.button_style.flag_type',
81
  'fn' => function( $flag_type ) {
82
  if ( $flag_type ) {
85
 
86
  return Helper_Flag_Type::RECTANGLE_MAT;
87
  },
88
+ ),
89
  'override_css' => 'custom_settings.button_style.custom_css',
90
  'email_translate' => 'custom_settings.translate_email',
91
  'active_search' => 'custom_settings.translate_search',
92
  'translate_amp' => 'custom_settings.translate_amp',
93
  'has_first_settings' => 'has_first_settings',
94
  'show_box_first_settings' => 'show_box_first_settings',
95
+ 'custom_urls' => (object) array(
96
  'path' => 'custom_urls',
97
  'fn' => function( $custom_urls ) {
98
  if ( $custom_urls ) {
99
  return $custom_urls;
100
  }
101
 
102
+ return array();
103
  },
104
+ ),
105
  'flag_css' => 'flag_css',
106
  'menu_switcher' => 'menu_switcher',
107
  'active_wc_reload' => 'active_wc_reload',
108
+ );
109
 
110
  return $schema;
111
  }
src/models/class-third-active-interface-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * Third Active
11
  *
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * Third Active
12
  *
src/notices/class-curl-weglot.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Models\Abstract_Notices_Weglot;
10
 
 
11
  /**
12
  * @since 2.0.1
13
  */
8
 
9
  use WeglotWP\Models\Abstract_Notices_Weglot;
10
 
11
+
12
  /**
13
  * @since 2.0.1
14
  */
src/notices/class-json-function-weglot.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Models\Abstract_Notices_Weglot;
10
 
 
11
  /**
12
  * @since 2.0.1
13
  */
8
 
9
  use WeglotWP\Models\Abstract_Notices_Weglot;
10
 
11
+
12
  /**
13
  * @since 2.0.1
14
  */
src/notices/class-no-configuration-weglot.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Models\Abstract_Notices_Weglot;
10
 
 
11
  /**
12
  * @since 2.0
13
  */
8
 
9
  use WeglotWP\Models\Abstract_Notices_Weglot;
10
 
11
+
12
  /**
13
  * @since 2.0
14
  */
src/notices/class-rewrite-module-weglot.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Models\Abstract_Notices_Weglot;
10
 
 
11
  /**
12
  * Rewrite module notice template
13
  *
8
 
9
  use WeglotWP\Models\Abstract_Notices_Weglot;
10
 
11
+
12
  /**
13
  * Rewrite module notice template
14
  *
src/services/class-button-service-weglot.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Helpers\Helper_Flag_Type;
10
 
 
11
  /**
12
  * Button services
13
  *
@@ -19,12 +20,12 @@ class Button_Service_Weglot {
19
  * @since 2.0
20
  */
21
  public function __construct() {
22
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
23
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
24
- $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
25
- $this->amp_services = weglot_get_service( 'Amp_Service_Weglot' );
26
- $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
27
- $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
28
  }
29
 
30
  /**
@@ -57,9 +58,9 @@ class Button_Service_Weglot {
57
  $name = '';
58
 
59
  if ( $with_name ) {
60
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
61
- $l = isset($language_code_rewrited[$language_entry->getIso639()]) ? $language_code_rewrited[$language_entry->getIso639()]:$language_entry->getIso639();
62
- $name = ( $is_fullname ) ? $language_entry->getLocalName() : strtoupper( $l );
63
  }
64
 
65
  return apply_filters( 'weglot_get_name_with_language_entry', $name, $language_entry );
@@ -71,8 +72,8 @@ class Button_Service_Weglot {
71
  * @return string
72
  */
73
  public function get_class_dropdown() {
74
- $is_dropdown = $this->option_services->get_option_button( 'is_dropdown' );
75
- $class = $is_dropdown ? 'weglot-dropdown ' : 'weglot-inline ';
76
 
77
  return apply_filters( 'weglot_get_class_dropdown', $class );
78
  }
@@ -88,8 +89,8 @@ class Button_Service_Weglot {
88
  * @param string $add_class
89
  */
90
  public function get_html( $add_class = '' ) {
91
- $private_mode = $this->option_services->get_option( 'private_mode' );
92
- $original_language = weglot_get_original_language();
93
 
94
  $private_all_languages = $this->private_language_services->private_mode_for_all_languages();
95
  if ( apply_filters( 'weglot_view_button_html', $private_all_languages ) ) {
@@ -98,8 +99,7 @@ class Button_Service_Weglot {
98
 
99
  $weglot_url = $this->request_url_services->get_weglot_url();
100
  $amp_regex = $this->amp_services->get_regex( true );
101
- $destination_language = weglot_get_destination_languages();
102
-
103
  $current_language = $this->request_url_services->get_current_language( false );
104
 
105
  if ( weglot_get_translate_amp_translation() && preg_match( '#' . $amp_regex . '#', $weglot_url->getUrl() ) === 1 ) {
@@ -109,15 +109,15 @@ class Button_Service_Weglot {
109
  $flag_class = $this->get_flag_class();
110
  $class_aside = $this->get_class_dropdown();
111
 
112
- $button_html = sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
113
  $button_html .= sprintf( "<aside data-wg-notranslate class='country-selector %s'>", $class_aside . $add_class );
114
 
115
  if ( ! empty( $original_language ) && ! empty( $destination_language ) ) {
116
  $current_language_entry = $this->language_services->get_current_language_entry_from_key( $current_language );
117
  $name = $this->get_name_with_language_entry( $current_language_entry );
118
 
119
- $uniq_id = 'wg' . uniqid( strtotime( 'now' ) ) . rand( 1, 1000 );
120
- $button_html .= sprintf( '<input id="%s" class="weglot_choice" type="checkbox" name="menu"/><label for="%s" class="wgcurrent wg-li weglot-lang weglot-language %s" data-code-language="%s"><span>%s</span></label>', esc_attr($uniq_id), esc_attr($uniq_id), esc_attr($flag_class . $current_language_entry->getIso639()), esc_attr($current_language_entry->getIso639()), esc_html($name) );
121
 
122
  $button_html .= '<ul>';
123
 
@@ -125,24 +125,24 @@ class Button_Service_Weglot {
125
 
126
  foreach ( $destination_language as $key => $key_code ) {
127
 
128
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
129
- $toTranslateLanguageIso = ($key = array_search($key_code,$language_code_rewrited)) ? $key:$key_code;
130
 
131
- if ( $key_code === $current_language || $this->private_language_services->is_active_private_mode_for_lang( $toTranslateLanguageIso ) ) {
132
  continue;
133
  }
134
 
135
- $button_html .= sprintf( '<li class="wg-li weglot-lang weglot-language %s" data-code-language="%s">', $flag_class . $toTranslateLanguageIso, $toTranslateLanguageIso );
136
 
137
- $current_language_entry = $this->language_services->get_current_language_entry_from_key( $toTranslateLanguageIso );
138
- $name = $this->get_name_with_language_entry( $current_language_entry );
139
 
140
  $link_button = $this->custom_url_services->get_link_button_with_key_code( $key_code );
141
 
142
  $button_html .= sprintf(
143
  '<a data-wg-notranslate href="%s">%s</a>',
144
- esc_url($link_button),
145
- esc_html($name)
146
  );
147
 
148
  $button_html .= '</li>';
8
 
9
  use WeglotWP\Helpers\Helper_Flag_Type;
10
 
11
+
12
  /**
13
  * Button services
14
  *
20
  * @since 2.0
21
  */
22
  public function __construct() {
23
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
24
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
25
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
26
+ $this->amp_services = weglot_get_service( 'Amp_Service_Weglot' );
27
+ $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
28
+ $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
29
  }
30
 
31
  /**
58
  $name = '';
59
 
60
  if ( $with_name ) {
61
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
62
+ $l = isset( $language_code_rewrited[ $language_entry->getIso639() ] ) ? $language_code_rewrited[ $language_entry->getIso639() ] : $language_entry->getIso639();
63
+ $name = ( $is_fullname ) ? $language_entry->getLocalName() : strtoupper( $l );
64
  }
65
 
66
  return apply_filters( 'weglot_get_name_with_language_entry', $name, $language_entry );
72
  * @return string
73
  */
74
  public function get_class_dropdown() {
75
+ $is_dropdown = $this->option_services->get_option_button( 'is_dropdown' );
76
+ $class = $is_dropdown ? 'weglot-dropdown ' : 'weglot-inline ';
77
 
78
  return apply_filters( 'weglot_get_class_dropdown', $class );
79
  }
89
  * @param string $add_class
90
  */
91
  public function get_html( $add_class = '' ) {
92
+ $private_mode = $this->option_services->get_option( 'private_mode' );
93
+ $original_language = weglot_get_original_language();
94
 
95
  $private_all_languages = $this->private_language_services->private_mode_for_all_languages();
96
  if ( apply_filters( 'weglot_view_button_html', $private_all_languages ) ) {
99
 
100
  $weglot_url = $this->request_url_services->get_weglot_url();
101
  $amp_regex = $this->amp_services->get_regex( true );
102
+ $destination_language = weglot_get_current_destination_languages();
 
103
  $current_language = $this->request_url_services->get_current_language( false );
104
 
105
  if ( weglot_get_translate_amp_translation() && preg_match( '#' . $amp_regex . '#', $weglot_url->getUrl() ) === 1 ) {
109
  $flag_class = $this->get_flag_class();
110
  $class_aside = $this->get_class_dropdown();
111
 
112
+ $button_html = sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
113
  $button_html .= sprintf( "<aside data-wg-notranslate class='country-selector %s'>", $class_aside . $add_class );
114
 
115
  if ( ! empty( $original_language ) && ! empty( $destination_language ) ) {
116
  $current_language_entry = $this->language_services->get_current_language_entry_from_key( $current_language );
117
  $name = $this->get_name_with_language_entry( $current_language_entry );
118
 
119
+ $uniq_id = 'wg' . uniqid( strtotime( 'now' ) ) . rand( 1, 1000 );
120
+ $button_html .= sprintf( '<input id="%s" class="weglot_choice" type="checkbox" name="menu"/><label for="%s" class="wgcurrent wg-li weglot-lang weglot-language %s" data-code-language="%s"><span>%s</span></label>', esc_attr( $uniq_id ), esc_attr( $uniq_id ), esc_attr( $flag_class . $current_language_entry->getIso639() ), esc_attr( $current_language_entry->getIso639() ), esc_html( $name ) );
121
 
122
  $button_html .= '<ul>';
123
 
125
 
126
  foreach ( $destination_language as $key => $key_code ) {
127
 
128
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
129
+ $to_translate_language_iso = ( $key = array_search( $key_code, $language_code_rewrited ) ) ? $key : $key_code;
130
 
131
+ if ( $key_code === $current_language || $this->private_language_services->is_active_private_mode_for_lang( $to_translate_language_iso ) ) {
132
  continue;
133
  }
134
 
135
+ $button_html .= sprintf( '<li class="wg-li weglot-lang weglot-language %s" data-code-language="%s">', $flag_class . $to_translate_language_iso, $to_translate_language_iso );
136
 
137
+ $current_language_entry = $this->language_services->get_current_language_entry_from_key( $to_translate_language_iso );
138
+ $name = $this->get_name_with_language_entry( $current_language_entry );
139
 
140
  $link_button = $this->custom_url_services->get_link_button_with_key_code( $key_code );
141
 
142
  $button_html .= sprintf(
143
  '<a data-wg-notranslate href="%s">%s</a>',
144
+ esc_url( $link_button ),
145
+ esc_html( $name )
146
  );
147
 
148
  $button_html .= '</li>';
src/services/class-custom-url-service-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * Custom URL services
11
  *
@@ -17,8 +18,8 @@ class Custom_Url_Service_Weglot {
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
  /**
@@ -29,7 +30,7 @@ class Custom_Url_Service_Weglot {
29
  */
30
  public function get_link( $key_code, $add_no_redirect = true ) {
31
 
32
- if( apply_filters( 'weglot_need_reset_postdata', false ) ) {
33
  wp_reset_postdata();
34
  }
35
 
@@ -40,34 +41,35 @@ class Custom_Url_Service_Weglot {
40
  $url_lang = $weglot_url->getForLanguage( $key_code );
41
  $original_language = weglot_get_original_language();
42
  $current_language = weglot_get_current_language();
43
- $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() && ! is_front_page() && ! is_home();
44
 
45
  if ( apply_filters( 'weglot_condition_test_custom_url', $condition_test_custom_url, $url_lang, $key_code ) ) {
46
- $slug_in_work = $request_without_language[ $index_entries ];
47
- $original_slug_in_work = $slug_in_work;
48
-
49
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
50
- if($current_language !== $original_language) {
51
- $toTranslateLanguageIso = ($key = array_search($current_language,$language_code_rewrited)) ? $key:$current_language;
52
- if ( isset( $custom_urls[ $toTranslateLanguageIso ] )) {
53
- $value_slug = array_key_exists($slug_in_work, $custom_urls[$toTranslateLanguageIso]) ? $custom_urls[$toTranslateLanguageIso][$slug_in_work] : false;
54
- if ( false !== $value_slug ) {
55
- $original_slug_in_work = $value_slug;
56
- }
57
- }
 
58
  }
59
 
60
- $toTranslateLanguageIso = ($key = array_search($key_code,$language_code_rewrited)) ? $key:$key_code;
61
- if ( isset( $custom_urls[ $toTranslateLanguageIso ] )) {
62
- $key_slug = array_search( $original_slug_in_work, $custom_urls[ $toTranslateLanguageIso ] ); //phpcs:ignore
63
- if ( false !== $key_slug ) {
64
- $url_lang = str_replace($slug_in_work, $key_slug, $url_lang);
65
- }
66
- }
67
- else {
68
-
69
- $url_lang = str_replace( $slug_in_work, $original_slug_in_work, $url_lang );
70
- }
71
  }
72
 
73
  $link_button = apply_filters( 'weglot_link_language', $url_lang, $key_code );
@@ -78,16 +80,16 @@ class Custom_Url_Service_Weglot {
78
  ( is_home() || is_front_page() ) && // Only for homepage
79
  $key_code === $original_language && // Only for original language
80
  $add_no_redirect // Example : for hreflang service
81
- ) {
82
  $link_button .= '?no_lredirect=true';
83
  } else {
84
- $link_button = preg_replace( '#\?no_lredirect=true$#', '', $link_button ); // Remove ending "?no_lredirect=true"
 
85
  }
86
 
87
  return apply_filters( 'weglot_get_link_with_key_code', $link_button );
88
  }
89
 
90
-
91
  /**
92
  * @since 2.3.0
93
  * @return string
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * Custom URL services
12
  *
18
  * @since 2.3.0
19
  */
20
  public function __construct() {
21
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
22
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
23
  }
24
 
25
  /**
30
  */
31
  public function get_link( $key_code, $add_no_redirect = true ) {
32
 
33
+ if ( apply_filters( 'weglot_need_reset_postdata', false ) ) {
34
  wp_reset_postdata();
35
  }
36
 
41
  $url_lang = $weglot_url->getForLanguage( $key_code );
42
  $original_language = weglot_get_original_language();
43
  $current_language = weglot_get_current_language();
44
+ $condition_test_custom_url = isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) && ! is_front_page() && ! is_home();
45
 
46
  if ( apply_filters( 'weglot_condition_test_custom_url', $condition_test_custom_url, $url_lang, $key_code ) ) {
47
+ $slug_in_work = $request_without_language[ $index_entries ];
48
+ $original_slug_in_work = $slug_in_work;
49
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
50
+ $original_slug_in_work = $request_without_language[ $index_entries ];
51
+ $current_language_iso = ( $key = array_search( $current_language, $language_code_rewrited ) ) ? $key : $current_language;
52
+
53
+ if (
54
+ $current_language_iso !== $original_language
55
+ && isset( $custom_urls[ $current_language_iso ] )
56
+ ) {
57
+ foreach ( $custom_urls[ $current_language_iso ] as $key => $value ) {
58
+ $original_slug_in_work = str_replace( '/' . $value . '/', '/' . $key . '/', $original_slug_in_work );
59
+ }
60
  }
61
 
62
+ $to_translate_language_iso = ( $key = array_search( $key_code, $language_code_rewrited ) ) ? $key : $key_code;
63
+
64
+ if ( isset( $custom_urls[ $to_translate_language_iso ] ) ) {
65
+ foreach ( $custom_urls[ $to_translate_language_iso ] as $key => $value ) {
66
+ $url_lang = str_replace( '/' . $value . '/', '/' . $key . '/', $url_lang );
67
+ }
68
+ } elseif ( isset( $custom_urls[ $current_language_iso ] ) ) {
69
+ foreach ( $custom_urls[ $current_language_iso ] as $key => $value ) {
70
+ $url_lang = str_replace( '/' . $key . '/', '/' . $value . '/', $url_lang );
71
+ }
72
+ }
73
  }
74
 
75
  $link_button = apply_filters( 'weglot_link_language', $url_lang, $key_code );
80
  ( is_home() || is_front_page() ) && // Only for homepage
81
  $key_code === $original_language && // Only for original language
82
  $add_no_redirect // Example : for hreflang service
83
+ ) {
84
  $link_button .= '?no_lredirect=true';
85
  } else {
86
+ // Remove ending "?no_lredirect=true"
87
+ $link_button = preg_replace( '#\?no_lredirect=true$#', '', $link_button );
88
  }
89
 
90
  return apply_filters( 'weglot_get_link_with_key_code', $link_button );
91
  }
92
 
 
93
  /**
94
  * @since 2.3.0
95
  * @return string
src/services/class-dom-checkers-service-weglot.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use Weglot\Util\Text;
10
 
 
11
  /**
12
  * Dom Checkers
13
  *
@@ -21,14 +22,17 @@ class Dom_Checkers_Service_Weglot {
21
  * @return array
22
  */
23
  public function get_dom_checkers() {
24
- $files = array_diff( scandir( __DIR__ . '/../domcheckers' ), [ '..', '.' ] );
25
- $checkers = array_map( function ( $filename ) {
26
- // Thanks WPCS :)
27
- $filename = Text::removeFileExtension( $filename );
28
- $filename = str_replace( 'class-', '', $filename );
29
- $filename = implode( '_', array_map( 'ucfirst', explode( '-', $filename ) ) );
30
- return '\\WeglotWP\\Domcheckers\\' . $filename;
31
- }, $files);
 
 
 
32
 
33
  return apply_filters( 'weglot_get_dom_checkers', $checkers );
34
  }
8
 
9
  use Weglot\Util\Text;
10
 
11
+
12
  /**
13
  * Dom Checkers
14
  *
22
  * @return array
23
  */
24
  public function get_dom_checkers() {
25
+ $files = array_diff( scandir( __DIR__ . '/../domcheckers' ), array( '..', '.' ) );
26
+ $checkers = array_map(
27
+ function ( $filename ) {
28
+ // Thanks WPCS :)
29
+ $filename = Text::removeFileExtension( $filename );
30
+ $filename = str_replace( 'class-', '', $filename );
31
+ $filename = implode( '_', array_map( 'ucfirst', explode( '-', $filename ) ) );
32
+ return '\\WeglotWP\\Domcheckers\\' . $filename;
33
+ },
34
+ $files
35
+ );
36
 
37
  return apply_filters( 'weglot_get_dom_checkers', $checkers );
38
  }
src/services/class-dom-listeners-service-weglot.php CHANGED
@@ -23,9 +23,9 @@ class Dom_Listeners_Service_Weglot {
23
  if ( '1' === WEGLOT_LIB_PARSER ) {
24
  return;
25
  }
26
- $this->dom_listeners = [
27
  'parser.crawler.after' => new \WeglotWP\Domlisteners\Meta_Listener_Weglot(),
28
- ];
29
  }
30
 
31
  /**
23
  if ( '1' === WEGLOT_LIB_PARSER ) {
24
  return;
25
  }
26
+ $this->dom_listeners = array(
27
  'parser.crawler.after' => new \WeglotWP\Domlisteners\Meta_Listener_Weglot(),
28
+ );
29
  }
30
 
31
  /**
src/services/class-email-translate-service-weglot.php CHANGED
@@ -6,11 +6,11 @@ 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
  */
@@ -20,8 +20,8 @@ class Email_Translate_Service_Weglot {
20
  * @since 2.3.0
21
  */
22
  public function __construct() {
23
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
24
- $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
25
  }
26
 
27
 
@@ -33,33 +33,33 @@ class Email_Translate_Service_Weglot {
33
  * @return array
34
  */
35
  public function translate_email( $args, $language ) {
36
- $api_key = $this->option_services->get_option( 'api_key' );
37
 
38
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
39
- $toTranslateLanguageIso = ($key = array_search($language,$language_code_rewrited)) ? $key:$language;
40
 
41
  if ( ! $api_key ) {
42
  return $args;
43
  }
44
 
45
  try {
46
- $original_language = weglot_get_original_language();
47
- $exclude_blocks = $this->option_services->get_exclude_blocks();
48
 
49
  $config = new ServerConfigProvider();
50
  $client = $this->parser_services->get_client();
51
  $parser = new Parser( $client, $config, $exclude_blocks );
52
- $translated_subject = $parser->translate( '<p>' . $args['subject'] . '</p>', $original_language, $toTranslateLanguageIso ); //phpcs:ignore
53
 
54
  $config = new ServerConfigProvider();
55
  $client = $this->parser_services->get_client();
56
  $parser = new Parser( $client, $config, $exclude_blocks );
57
- $translated_message = $parser->translate( $args['message'], $original_language, $toTranslateLanguageIso ); //phpcs:ignore
58
 
59
- return [
60
  'subject' => $translated_subject,
61
  'message' => $translated_message,
62
- ];
63
  } catch ( \Exception $e ) {
64
  return $args;
65
  }
6
  exit;
7
  }
8
 
 
9
  use Weglot\Client\Client;
10
  use Weglot\Parser\Parser;
11
  use Weglot\Parser\ConfigProvider\ServerConfigProvider;
12
 
13
+
14
  /**
15
  * @since 2.3.0
16
  */
20
  * @since 2.3.0
21
  */
22
  public function __construct() {
23
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
24
+ $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
25
  }
26
 
27
 
33
  * @return array
34
  */
35
  public function translate_email( $args, $language ) {
36
+ $api_key = $this->option_services->get_option( 'api_key' );
37
 
38
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
39
+ $to_translate_language_iso = ( $key = array_search( $language, $language_code_rewrited ) ) ? $key : $language;
40
 
41
  if ( ! $api_key ) {
42
  return $args;
43
  }
44
 
45
  try {
46
+ $original_language = weglot_get_original_language();
47
+ $exclude_blocks = $this->option_services->get_exclude_blocks();
48
 
49
  $config = new ServerConfigProvider();
50
  $client = $this->parser_services->get_client();
51
  $parser = new Parser( $client, $config, $exclude_blocks );
52
+ $translated_subject = $parser->translate( '<p>' . $args['subject'] . '</p>', $original_language, $to_translate_language_iso ); //phpcs:ignore
53
 
54
  $config = new ServerConfigProvider();
55
  $client = $this->parser_services->get_client();
56
  $parser = new Parser( $client, $config, $exclude_blocks );
57
+ $translated_message = $parser->translate( $args['message'], $original_language, $to_translate_language_iso ); //phpcs:ignore
58
 
59
+ return array(
60
  'subject' => $translated_subject,
61
  'message' => $translated_message,
62
+ );
63
  } catch ( \Exception $e ) {
64
  return $args;
65
  }
src/services/class-generate-switcher-service-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  *
11
  * @since 2.3.0
@@ -16,11 +17,11 @@ class Generate_Switcher_Service_Weglot {
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
  /**
@@ -34,8 +35,8 @@ class Generate_Switcher_Service_Weglot {
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
  }
@@ -46,9 +47,9 @@ class Generate_Switcher_Service_Weglot {
46
  * @param string $dom
47
  * @return string
48
  */
49
- public function check_weglot_menu( $dom ) {
50
- return apply_filters( 'weglot_replace_weglot_menu', $dom );
51
- }
52
 
53
  /**
54
  * @since 2.3.0
@@ -62,8 +63,8 @@ class Generate_Switcher_Service_Weglot {
62
  }
63
 
64
  // Place the button if not in the page
65
- $button_html = $this->button_services->get_html( 'weglot-default' );
66
- $dom = ( strpos( $dom, '</body>' ) !== false) ? str_replace( '</body>', $button_html . ' </body>', $dom ) : str_replace( '</footer>', $button_html . ' </footer>', $dom );
67
 
68
  return apply_filters( 'weglot_render_default_button', $dom );
69
  }
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  *
12
  * @since 2.3.0
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
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
23
+ $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
24
+ $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
25
  }
26
 
27
  /**
35
  return $dom;
36
  }
37
 
38
+ $button_html = $this->button_services->get_html( 'weglot-shortcode' );
39
+ $dom = str_replace( '<div id="weglot_here"></div>', $button_html, $dom );
40
 
41
  return apply_filters( 'weglot_replace_div_id', $dom );
42
  }
47
  * @param string $dom
48
  * @return string
49
  */
50
+ public function check_weglot_menu( $dom ) {
51
+ return apply_filters( 'weglot_replace_weglot_menu', $dom );
52
+ }
53
 
54
  /**
55
  * @since 2.3.0
63
  }
64
 
65
  // Place the button if not in the page
66
+ $button_html = $this->button_services->get_html( 'weglot-default' );
67
+ $dom = ( strpos( $dom, '</body>' ) !== false ) ? str_replace( '</body>', $button_html . ' </body>', $dom ) : str_replace( '</footer>', $button_html . ' </footer>', $dom );
68
 
69
  return apply_filters( 'weglot_render_default_button', $dom );
70
  }
src/services/class-href-lang-service-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * @since 2.3.0
11
  */
@@ -16,9 +17,9 @@ class Href_Lang_Service_Weglot {
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
  /**
@@ -37,8 +38,8 @@ class Href_Lang_Service_Weglot {
37
  continue;
38
  }
39
 
40
- $url = $this->custom_url_services->get_link( $language, false );
41
- $render .= '<link rel="alternate" hreflang="' . $language . '" href="' . esc_url($url) . '"/>' . "\n";
42
  }
43
  } catch ( \Exception $e ) {
44
  $render = $this->request_url_services->get_weglot_url()->generateHrefLangsTags();
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * @since 2.3.0
12
  */
17
  * @since 2.3.0
18
  */
19
  public function __construct() {
20
+ $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
21
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
22
+ $this->private_language_service = weglot_get_service( 'Private_Language_Service_Weglot' );
23
  }
24
 
25
  /**
38
  continue;
39
  }
40
 
41
+ $url = $this->custom_url_services->get_link( $language, false );
42
+ $render .= '<link rel="alternate" hreflang="' . $language . '" href="' . esc_url( $url ) . '"/>' . "\n";
43
  }
44
  } catch ( \Exception $e ) {
45
  $render = $this->request_url_services->get_weglot_url()->generateHrefLangsTags();
src/services/class-language-service-weglot.php CHANGED
@@ -6,12 +6,12 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use Weglot\Client\Endpoint\Languages;
11
  use Weglot\Client\Client;
12
  use Weglot\Client\Api\LanguageCollection;
13
  use Weglot\Client\Factory\Languages as LanguagesFactory;
14
 
 
15
  /**
16
  * Language service
17
  *
@@ -44,19 +44,19 @@ class Language_Service_Weglot {
44
  * @param array $params
45
  * @return array
46
  */
47
- public function get_languages_available( $params = [] ) {
48
  if ( null !== $this->languages ) {
49
  return $this->languages;
50
  }
51
 
52
- $client = weglot_get_service( 'Parser_Service_Weglot' )->get_client();
53
 
54
- $languages = new Languages( $client );
55
- $this->languages = $languages->handle();
56
 
57
  if ( isset( $params['sort'] ) && $params['sort'] ) {
58
  $this->languages = $this->languages->jsonSerialize();
59
- usort( $this->languages, [ $this, 'compare_language' ] );
60
 
61
  $language_collection = new LanguageCollection();
62
 
@@ -79,8 +79,8 @@ class Language_Service_Weglot {
79
  */
80
  public function get_language( $key_code ) {
81
 
82
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
83
- $language = ($key = array_search($key_code,$language_code_rewrited)) ? $this->get_languages_available()[ $key ]:$this->get_languages_available()[ $key_code ];
84
  return $language;
85
  }
86
 
@@ -90,15 +90,44 @@ class Language_Service_Weglot {
90
  * @param null|string $type
91
  */
92
  public function get_languages_configured( $type = null ) {
93
- $languages = [];
94
  $original_language = weglot_get_original_language();
95
 
96
- if( $original_language ){
97
  $languages[] = $original_language;
98
  }
99
- $languages = array_merge( $languages, weglot_get_destination_languages() );
100
 
101
- $languages_object = [];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  foreach ( $languages as $language ) {
103
  switch ( $type ) {
104
  case 'code':
@@ -120,10 +149,11 @@ class Language_Service_Weglot {
120
  */
121
  public function get_current_language_entry_from_key( $key_code ) {
122
 
123
- $languages = $this->get_languages_available();
124
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
125
- if($key = array_search($key_code,$language_code_rewrited))
126
- $key_code = $key;
 
127
 
128
  if ( isset( $languages[ $key_code ] ) ) {
129
  $current_language_entry = $languages[ $key_code ];
6
  exit;
7
  }
8
 
 
9
  use Weglot\Client\Endpoint\Languages;
10
  use Weglot\Client\Client;
11
  use Weglot\Client\Api\LanguageCollection;
12
  use Weglot\Client\Factory\Languages as LanguagesFactory;
13
 
14
+
15
  /**
16
  * Language service
17
  *
44
  * @param array $params
45
  * @return array
46
  */
47
+ public function get_languages_available( $params = array() ) {
48
  if ( null !== $this->languages ) {
49
  return $this->languages;
50
  }
51
 
52
+ $client = weglot_get_service( 'Parser_Service_Weglot' )->get_client();
53
 
54
+ $languages = new Languages( $client );
55
+ $this->languages = $languages->handle();
56
 
57
  if ( isset( $params['sort'] ) && $params['sort'] ) {
58
  $this->languages = $this->languages->jsonSerialize();
59
+ usort( $this->languages, array( $this, 'compare_language' ) );
60
 
61
  $language_collection = new LanguageCollection();
62
 
79
  */
80
  public function get_language( $key_code ) {
81
 
82
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
83
+ $language = ( $key = array_search( $key_code, $language_code_rewrited ) ) ? $this->get_languages_available()[ $key ] : $this->get_languages_available()[ $key_code ];
84
  return $language;
85
  }
86
 
90
  * @param null|string $type
91
  */
92
  public function get_languages_configured( $type = null ) {
93
+ $languages = array();
94
  $original_language = weglot_get_original_language();
95
 
96
+ if ( $original_language ) {
97
  $languages[] = $original_language;
98
  }
99
+ $languages = array_merge( $languages, weglot_get_destination_languages() );
100
 
101
+ $languages_object = array();
102
+ foreach ( $languages as $language ) {
103
+ switch ( $type ) {
104
+ case 'code':
105
+ $languages_object[] = $this->get_language( $language )->getIso639();
106
+ break;
107
+ default:
108
+ $languages_object[] = $this->get_language( $language );
109
+ break;
110
+ }
111
+ }
112
+ return $languages_object;
113
+ }
114
+
115
+ /**
116
+ * @since 2.0
117
+ * @return array
118
+ * @param null|string $type
119
+ */
120
+ public function get_current_languages_configured( $type = null ) {
121
+
122
+ $languages = array();
123
+ $original_language = weglot_get_original_language();
124
+
125
+ if ( $original_language ) {
126
+ $languages[] = $original_language;
127
+ }
128
+ $languages = array_merge( $languages, weglot_get_current_destination_languages() );
129
+
130
+ $languages_object = array();
131
  foreach ( $languages as $language ) {
132
  switch ( $type ) {
133
  case 'code':
149
  */
150
  public function get_current_language_entry_from_key( $key_code ) {
151
 
152
+ $languages = $this->get_languages_available();
153
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
154
+ if ( $key = array_search( $key_code, $language_code_rewrited ) ) {
155
+ $key_code = $key;
156
+ }
157
 
158
  if ( isset( $languages[ $key_code ] ) ) {
159
  $current_language_entry = $languages[ $key_code ];
src/services/class-menu-options-service-weglot.php CHANGED
@@ -6,9 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Helpers\Helper_Menu_Options_Weglot;
11
 
 
12
  /**
13
  * @since 2.4.0
14
  */
@@ -28,9 +28,15 @@ class Menu_Options_Service_Weglot {
28
  public function get_options_default() {
29
  $keys = Helper_Menu_Options_Weglot::get_keys();
30
 
31
- return apply_filters( 'weglot_menu_switcher_options_default', array_map( function() {
32
- return false;
33
- }, array_flip( $keys ) ) );
 
 
 
 
 
 
34
  }
35
 
36
  /**
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Helpers\Helper_Menu_Options_Weglot;
10
 
11
+
12
  /**
13
  * @since 2.4.0
14
  */
28
  public function get_options_default() {
29
  $keys = Helper_Menu_Options_Weglot::get_keys();
30
 
31
+ return apply_filters(
32
+ 'weglot_menu_switcher_options_default',
33
+ array_map(
34
+ function() {
35
+ return false;
36
+ },
37
+ array_flip( $keys )
38
+ )
39
+ );
40
  }
41
 
42
  /**
src/services/class-migration-service-weglot.php CHANGED
@@ -21,7 +21,7 @@ class Migration_Service_Weglot {
21
  * @since 2.0
22
  */
23
  public function __construct() {
24
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
  }
26
  }
27
 
21
  * @since 2.0
22
  */
23
  public function __construct() {
24
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
  }
26
  }
27
 
src/services/class-multisite-service-weglot.php CHANGED
@@ -18,7 +18,7 @@ class Multisite_Service_Weglot {
18
  * @since 2.0
19
  */
20
  public function __construct() {
21
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
22
  }
23
 
24
  /**
@@ -27,12 +27,14 @@ class Multisite_Service_Weglot {
27
  * @return array
28
  */
29
  public function get_list_of_network_path() {
30
- $paths = [];
31
 
32
  if ( is_multisite() ) {
33
- $sites = \get_sites( [
34
- 'number' => 0,
35
- ] );
 
 
36
 
37
  foreach ( $sites as $site ) {
38
  $path = $site->path;
18
  * @since 2.0
19
  */
20
  public function __construct() {
21
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
22
  }
23
 
24
  /**
27
  * @return array
28
  */
29
  public function get_list_of_network_path() {
30
+ $paths = array();
31
 
32
  if ( is_multisite() ) {
33
+ $sites = \get_sites(
34
+ array(
35
+ 'number' => 0,
36
+ )
37
+ );
38
 
39
  foreach ( $sites as $site ) {
40
  $path = $site->path;
src/services/class-option-service-weglot.php CHANGED
@@ -13,6 +13,7 @@ use WeglotWP\Models\Schema_Option_V3;
13
  use WeglotWP\Helpers\Helper_Flag_Type;
14
  use WeglotWP\Helpers\Helper_API;
15
 
 
16
  /**
17
  * Option services
18
  *
@@ -26,47 +27,47 @@ class Option_Service_Weglot {
26
  /**
27
  * @var array
28
  */
29
- protected $options_default = [
30
- 'api_key_private' => '',
31
- 'api_key' => '',
32
- 'language_from' => 'en',
33
- 'languages' => [],
34
- 'auto_switch' => false,
35
- 'auto_switch_fallback' => null,
36
- 'excluded_blocks' => [],
37
- 'excluded_paths' => [],
38
- 'custom_settings' => [
39
- 'translate_email' => false,
40
- 'translate_amp' => false,
41
- 'translate_search' => false,
42
- 'button_style' => [
43
- 'full_name' => true,
44
- 'with_name' => true,
45
- 'is_dropdown' => true,
46
- 'with_flags' => true,
47
- 'flag_type' => Helper_Flag_Type::RECTANGLE_MAT,
48
- 'custom_css' => '',
49
- ],
50
- 'rtl_ltr_style' => '',
51
- 'active_wc_reload' => true,
52
- 'flag_css' => '',
53
- ],
54
- 'allowed' => true,
55
- 'has_first_settings' => true,
56
- 'show_box_first_settings' => false,
57
- ];
58
 
59
  /**
60
  * @var array
61
  */
62
- protected $options_bdd_default = [
63
- 'has_first_settings' => true,
64
- 'show_box_first_settings' => false,
65
- 'menu_switcher' => [],
66
- 'custom_urls' => [],
67
- 'flag_css' => '',
68
- 'active_wc_reload' => true,
69
- ];
70
 
71
  /**
72
  * @since 3.0.0
@@ -93,52 +94,54 @@ class Option_Service_Weglot {
93
  */
94
  protected function get_options_from_cdn_with_api_key( $api_key ) {
95
  if ( $this->options_cdn ) {
96
- return [
97
  'success' => true,
98
  'result' => $this->options_cdn,
99
- ];
100
  }
101
 
102
  $cache_transient = apply_filters( 'weglot_get_options_from_cdn_cache', true );
103
 
104
- if( $cache_transient ) {
105
  $options = get_transient( 'weglot_cache_cdn', false );
106
- if( $options ) {
107
  $this->options_cdn = $options;
108
- return [
109
  'success' => true,
110
  'result' => $this->options_cdn,
111
- ];
112
  }
113
  }
114
 
115
- $key = str_replace( 'wg_', '', $api_key );
116
- $url = sprintf( '%s%s.json', Helper_API::get_cdn_url(), $key );
117
 
118
- $response = wp_remote_get( $url, [
119
- 'timeout' => 15,
120
- ] );
 
 
 
121
 
122
  try {
123
  if ( is_wp_error( $response ) ) {
124
  $response = $this->get_options_from_api_with_api_key( $this->get_api_key_private() );
125
- $body = $response["result"];
126
- }
127
- else{
128
- $body = json_decode( $response['body'], true );
129
  }
130
  $this->options_cdn = $body;
131
 
132
  set_transient( 'weglot_cache_cdn', $body, apply_filters( 'weglot_get_options_from_cdn_cache_duration', 300 ) );
133
 
134
- return [
135
  'success' => true,
136
  'result' => $body,
137
- ];
138
  } catch ( \Exception $th ) {
139
- return [
140
  'success' => false,
141
- ];
142
  }
143
  }
144
 
@@ -149,51 +152,54 @@ class Option_Service_Weglot {
149
  */
150
  public function get_options_from_api_with_api_key( $api_key ) {
151
  if ( $this->options_from_api ) {
152
- return [
153
  'success' => true,
154
  'result' => $this->options_from_api,
155
- ];
156
  }
157
 
158
- $url = sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $api_key );
159
 
160
- $response = wp_remote_get( $url, [
161
- 'timeout' => 15,
162
- ] );
 
 
 
163
 
164
  if ( is_wp_error( $response ) ) {
165
- return [
166
  'success' => false,
167
  'result' => $this->options_default,
168
- ];
169
  }
170
 
171
  try {
172
  $body = json_decode( $response['body'], true );
173
 
174
  if ( null === $body ) {
175
- return [
176
  'success' => false,
177
  'result' => $this->options_default,
178
- ];
179
  }
180
 
181
  $options = apply_filters( 'weglot_get_options', array_merge( $this->get_options_bdd_v3(), $body ) );
182
  $options['api_key_private'] = $this->get_api_key_private();
183
  if ( empty( $options['custom_settings']['menu_switcher'] ) ) {
184
- $menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
185
- $options['custom_settings']['menu_switcher'] = $menu_options_services->get_options_default();
186
  }
187
  $this->options_from_api = $options;
188
 
189
- return [
190
  'success' => true,
191
  'result' => $options,
192
- ];
193
  } catch ( \Exception $e ) {
194
- return [
195
  'success' => false,
196
- ];
197
  }
198
  }
199
 
@@ -210,7 +216,7 @@ class Option_Service_Weglot {
210
  $options_v2['api_key_private'] = $options_v2['api_key'];
211
  }
212
  if ( ! array_key_exists( 'custom_urls', $options_v2 ) || ! $options_v2['custom_urls'] ) {
213
- $options_v2['custom_urls'] = [];
214
  }
215
  return $options_v2;
216
  }
@@ -299,24 +305,27 @@ class Option_Service_Weglot {
299
  * @return array
300
  */
301
  public function save_options_to_weglot( $options ) {
302
- $response = wp_remote_post( sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $options['api_key_private'] ), [
303
- 'body' => json_encode( $options ), //phpcs: ignore
304
- 'headers' => [
305
- 'technology' => 'wordpress',
306
- 'Content-Type' => 'application/json; charset=utf-8',
307
- ],
308
- ] );
 
 
 
309
 
310
  if ( is_wp_error( $response ) ) {
311
- return [
312
  'success' => false,
313
- ];
314
  }
315
 
316
- return [
317
  'success' => true,
318
  'result' => json_decode( $response['body'], true ),
319
- ];
320
  }
321
 
322
  /**
@@ -327,7 +336,7 @@ class Option_Service_Weglot {
327
  public function get_option_custom_settings( $key ) {
328
  $options = $this->get_options();
329
 
330
- if( ! array_key_exists( 'custom_settings', $options ) ) {
331
  return $this->get_option( $key );
332
  }
333
 
@@ -350,7 +359,7 @@ class Option_Service_Weglot {
350
  return null;
351
  }
352
 
353
- return $options[ $key ];
354
  }
355
 
356
  /**
@@ -381,34 +390,37 @@ class Option_Service_Weglot {
381
  * @return array
382
  */
383
  public function get_exclude_blocks() {
384
- $exclude_blocks = $this->get_option( 'exclude_blocks' );
385
 
386
  // WordPress
387
- $exclude_blocks[] = '#wpadminbar';
388
 
389
  // Weglot Switcher
390
- $exclude_blocks[] = '.menu-item-weglot';
391
- $exclude_blocks[] = '.menu-item-weglot a';
392
 
393
  // Material Icons
394
- $exclude_blocks[] = '.material-icons';
395
 
396
  // Font Awesome
397
- $exclude_blocks[] = '.fas';
398
- $exclude_blocks[] = '.far';
399
- $exclude_blocks[] = '.fad';
400
 
401
  // Plugin Query Monitor
402
- $exclude_blocks[] = '#query-monitor';
403
- $exclude_blocks[] = '#query-monitor-main';
404
 
405
  // Plugin Woocommerce
406
- $exclude_blocks[] = '.mini-cart-counter';
407
- $exclude_blocks[] = '.amount'; //Added to prevent prices to pass
408
- $exclude_blocks[] = 'address';
409
 
410
  // Plugin SecuPress
411
- $exclude_blocks[] = '#secupress-donttranslate';
 
 
 
412
 
413
  return apply_filters( 'weglot_exclude_blocks', $exclude_blocks );
414
  }
@@ -418,16 +430,57 @@ class Option_Service_Weglot {
418
  * @version 3.0.0
419
  * @return array
420
  */
421
- public function get_destination_languages() {
422
- $destination_languages = $this->get_option( 'destination_language' );
 
 
 
 
 
 
 
 
 
 
423
 
424
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
425
- $destination_languages = array_map(function ($v) use ($language_code_rewrited) {
426
- return isset($language_code_rewrited[$v]) ? $language_code_rewrited[$v] : $v;
427
- }, $destination_languages);
428
  return apply_filters( 'weglot_destination_languages', $destination_languages );
429
  }
430
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
  /**
432
  * @since 2.0
433
  * @return array
@@ -435,10 +488,24 @@ class Option_Service_Weglot {
435
  public function get_exclude_urls() {
436
  $list_exclude_urls = $this->get_option( 'exclude_urls' );
437
  $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
438
- $exclude_urls = [];
 
439
  if ( ! empty( $list_exclude_urls ) ) {
440
  foreach ( $list_exclude_urls as $item ) {
441
  if ( is_array( $item ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  $regex = new Regex( $item['type'], $request_url_services->url_to_relative( $item['value'] ) );
443
  $exclude_urls[] = $regex->getRegex();
444
  } else {
@@ -446,12 +513,13 @@ class Option_Service_Weglot {
446
  }
447
  }
448
  }
449
- $exclude_urls[] = '/wp-login.php';
450
- $exclude_urls[] = '/sitemaps_xsl.xsl';
451
- $exclude_urls[] = '/sitemaps.xml';
452
- $exclude_urls[] = 'wp-comments-post.php';
453
- $exclude_urls[] = '/ct_template'; // Compatibility Oxygen
454
- $exclude_urls[] = '/main-sitemap.xsl'; // SEO by Rank Math
 
455
 
456
  $translate_amp = weglot_get_translate_amp_translation();
457
  if ( ! $translate_amp ) {
@@ -459,9 +527,65 @@ class Option_Service_Weglot {
459
  }
460
 
461
  // array_map : Need only for those who use the filter
462
- return apply_filters( 'weglot_exclude_urls', array_map( function( $value ) use ( $request_url_services ) {
463
- return $request_url_services->url_to_relative( $value );
464
- }, $exclude_urls ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
  }
466
 
467
  /**
@@ -499,7 +623,7 @@ class Option_Service_Weglot {
499
  public function set_options( $options ) {
500
  $key = sprintf( '%s-%s', WEGLOT_SLUG, 'v3' );
501
  update_option( $key, $options );
502
- wp_cache_delete ( $key );
503
 
504
  return $this;
505
  }
@@ -529,9 +653,9 @@ class Option_Service_Weglot {
529
  * @return any
530
  */
531
  public function get_option_by_key_v3( $key ) {
532
- $options = $this->get_options_bdd_v3();
533
 
534
- if( ! array_key_exists( $key, $options ) ) {
535
  return null;
536
  }
537
 
13
  use WeglotWP\Helpers\Helper_Flag_Type;
14
  use WeglotWP\Helpers\Helper_API;
15
 
16
+
17
  /**
18
  * Option services
19
  *
27
  /**
28
  * @var array
29
  */
30
+ protected $options_default = array(
31
+ 'api_key_private' => '',
32
+ 'api_key' => '',
33
+ 'language_from' => 'en',
34
+ 'languages' => array(),
35
+ 'auto_switch' => false,
36
+ 'auto_switch_fallback' => null,
37
+ 'excluded_blocks' => array(),
38
+ 'excluded_paths' => array(),
39
+ 'custom_settings' => array(
40
+ 'translate_email' => false,
41
+ 'translate_amp' => false,
42
+ 'translate_search' => false,
43
+ 'button_style' => array(
44
+ 'full_name' => true,
45
+ 'with_name' => true,
46
+ 'is_dropdown' => true,
47
+ 'with_flags' => true,
48
+ 'flag_type' => Helper_Flag_Type::RECTANGLE_MAT,
49
+ 'custom_css' => '',
50
+ ),
51
+ 'rtl_ltr_style' => '',
52
+ 'active_wc_reload' => true,
53
+ 'flag_css' => '',
54
+ ),
55
+ 'allowed' => true,
56
+ 'has_first_settings' => true,
57
+ 'show_box_first_settings' => false,
58
+ );
59
 
60
  /**
61
  * @var array
62
  */
63
+ protected $options_bdd_default = array(
64
+ 'has_first_settings' => true,
65
+ 'show_box_first_settings' => false,
66
+ 'menu_switcher' => array(),
67
+ 'custom_urls' => array(),
68
+ 'flag_css' => '',
69
+ 'active_wc_reload' => true,
70
+ );
71
 
72
  /**
73
  * @since 3.0.0
94
  */
95
  protected function get_options_from_cdn_with_api_key( $api_key ) {
96
  if ( $this->options_cdn ) {
97
+ return array(
98
  'success' => true,
99
  'result' => $this->options_cdn,
100
+ );
101
  }
102
 
103
  $cache_transient = apply_filters( 'weglot_get_options_from_cdn_cache', true );
104
 
105
+ if ( $cache_transient ) {
106
  $options = get_transient( 'weglot_cache_cdn', false );
107
+ if ( $options ) {
108
  $this->options_cdn = $options;
109
+ return array(
110
  'success' => true,
111
  'result' => $this->options_cdn,
112
+ );
113
  }
114
  }
115
 
116
+ $key = str_replace( 'wg_', '', $api_key );
117
+ $url = sprintf( '%s%s.json', Helper_API::get_cdn_url(), $key );
118
 
119
+ $response = wp_remote_get(
120
+ $url,
121
+ array(
122
+ 'timeout' => 15,
123
+ )
124
+ );
125
 
126
  try {
127
  if ( is_wp_error( $response ) ) {
128
  $response = $this->get_options_from_api_with_api_key( $this->get_api_key_private() );
129
+ $body = $response['result'];
130
+ } else {
131
+ $body = json_decode( $response['body'], true );
 
132
  }
133
  $this->options_cdn = $body;
134
 
135
  set_transient( 'weglot_cache_cdn', $body, apply_filters( 'weglot_get_options_from_cdn_cache_duration', 300 ) );
136
 
137
+ return array(
138
  'success' => true,
139
  'result' => $body,
140
+ );
141
  } catch ( \Exception $th ) {
142
+ return array(
143
  'success' => false,
144
+ );
145
  }
146
  }
147
 
152
  */
153
  public function get_options_from_api_with_api_key( $api_key ) {
154
  if ( $this->options_from_api ) {
155
+ return array(
156
  'success' => true,
157
  'result' => $this->options_from_api,
158
+ );
159
  }
160
 
161
+ $url = sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $api_key );
162
 
163
+ $response = wp_remote_get(
164
+ $url,
165
+ array(
166
+ 'timeout' => 15,
167
+ )
168
+ );
169
 
170
  if ( is_wp_error( $response ) ) {
171
+ return array(
172
  'success' => false,
173
  'result' => $this->options_default,
174
+ );
175
  }
176
 
177
  try {
178
  $body = json_decode( $response['body'], true );
179
 
180
  if ( null === $body ) {
181
+ return array(
182
  'success' => false,
183
  'result' => $this->options_default,
184
+ );
185
  }
186
 
187
  $options = apply_filters( 'weglot_get_options', array_merge( $this->get_options_bdd_v3(), $body ) );
188
  $options['api_key_private'] = $this->get_api_key_private();
189
  if ( empty( $options['custom_settings']['menu_switcher'] ) ) {
190
+ $menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
191
+ $options['custom_settings']['menu_switcher'] = $menu_options_services->get_options_default();
192
  }
193
  $this->options_from_api = $options;
194
 
195
+ return array(
196
  'success' => true,
197
  'result' => $options,
198
+ );
199
  } catch ( \Exception $e ) {
200
+ return array(
201
  'success' => false,
202
+ );
203
  }
204
  }
205
 
216
  $options_v2['api_key_private'] = $options_v2['api_key'];
217
  }
218
  if ( ! array_key_exists( 'custom_urls', $options_v2 ) || ! $options_v2['custom_urls'] ) {
219
+ $options_v2['custom_urls'] = array();
220
  }
221
  return $options_v2;
222
  }
305
  * @return array
306
  */
307
  public function save_options_to_weglot( $options ) {
308
+ $response = wp_remote_post(
309
+ sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $options['api_key_private'] ),
310
+ array(
311
+ 'body' => json_encode( $options ), //phpcs: ignore
312
+ 'headers' => array(
313
+ 'technology' => 'wordpress',
314
+ 'Content-Type' => 'application/json; charset=utf-8',
315
+ ),
316
+ )
317
+ );
318
 
319
  if ( is_wp_error( $response ) ) {
320
+ return array(
321
  'success' => false,
322
+ );
323
  }
324
 
325
+ return array(
326
  'success' => true,
327
  'result' => json_decode( $response['body'], true ),
328
+ );
329
  }
330
 
331
  /**
336
  public function get_option_custom_settings( $key ) {
337
  $options = $this->get_options();
338
 
339
+ if ( ! array_key_exists( 'custom_settings', $options ) ) {
340
  return $this->get_option( $key );
341
  }
342
 
359
  return null;
360
  }
361
 
362
+ return apply_filters( 'weglot_get_option', $options[ $key ], $key, $options );
363
  }
364
 
365
  /**
390
  * @return array
391
  */
392
  public function get_exclude_blocks() {
393
+ $exclude_blocks = $this->get_option( 'exclude_blocks' );
394
 
395
  // WordPress
396
+ $exclude_blocks[] = '#wpadminbar';
397
 
398
  // Weglot Switcher
399
+ $exclude_blocks[] = '.menu-item-weglot';
400
+ $exclude_blocks[] = '.menu-item-weglot a';
401
 
402
  // Material Icons
403
+ $exclude_blocks[] = '.material-icons';
404
 
405
  // Font Awesome
406
+ $exclude_blocks[] = '.fas';
407
+ $exclude_blocks[] = '.far';
408
+ $exclude_blocks[] = '.fad';
409
 
410
  // Plugin Query Monitor
411
+ $exclude_blocks[] = '#query-monitor';
412
+ $exclude_blocks[] = '#query-monitor-main';
413
 
414
  // Plugin Woocommerce
415
+ $exclude_blocks[] = '.mini-cart-counter';
416
+ $exclude_blocks[] = '.amount'; //Added to prevent prices to pass
417
+ $exclude_blocks[] = 'address';
418
 
419
  // Plugin SecuPress
420
+ $exclude_blocks[] = '#secupress-donttranslate';
421
+
422
+ // Plugin Gamipress
423
+ $exclude_blocks[] = '.gamipress-share-button';
424
 
425
  return apply_filters( 'weglot_exclude_blocks', $exclude_blocks );
426
  }
430
  * @version 3.0.0
431
  * @return array
432
  */
433
+ public function get_destination_languages( $formated = false ) {
434
+ $destination_languages = $this->get_option( 'destination_language' );
435
+
436
+ if ( ! $formated ) {
437
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
438
+ $destination_languages = array_map(
439
+ function ( $v ) use ( $language_code_rewrited ) {
440
+ return isset( $language_code_rewrited[ $v ] ) ? $language_code_rewrited[ $v ] : $v;
441
+ },
442
+ $destination_languages
443
+ );
444
+ }
445
 
 
 
 
 
446
  return apply_filters( 'weglot_destination_languages', $destination_languages );
447
  }
448
 
449
+
450
+ /**
451
+ * @since 3.2.0
452
+ * @return array
453
+ */
454
+ public function get_current_destination_languages( $current_url = null ) {
455
+ $destination_languages = $this->get_destination_languages();
456
+ $request_url_service = weglot_get_request_url_service();
457
+
458
+ if ( is_null( $current_url ) ) {
459
+ $current_url = $request_url_service->get_full_url_no_language();
460
+ }
461
+
462
+ $current_url = $request_url_service->url_to_relative( $current_url );
463
+ $exclude_urls_by_languages = $this->get_exclude_urls_by_languages();
464
+ $custom_urls = $request_url_service->option_services->get_option( 'custom_urls' );
465
+ $current_language = $request_url_service->get_current_language();
466
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
467
+ $current_language_iso = ( $key = array_search( $current_language, $language_code_rewrited ) ) ? $key : $current_language;
468
+
469
+ if ( isset( $custom_urls[ $current_language_iso ] ) ) {
470
+ foreach ( $custom_urls[ $current_language_iso ] as $key => $value ) {
471
+ $current_url = str_replace( '/' . $key . '/', '/' . $value . '/', $current_url );
472
+ }
473
+ }
474
+
475
+ foreach ( $exclude_urls_by_languages as $item ) {
476
+ if ( preg_match( '#' . $item['value'] . '#', $current_url ) != 0 ) {
477
+ $destination_languages = array_diff( $destination_languages, $item['excluded_languages'] );
478
+ }
479
+ }
480
+
481
+ return apply_filters( 'weglot_current_destination_languages', $destination_languages, $current_url );
482
+ }
483
+
484
  /**
485
  * @since 2.0
486
  * @return array
488
  public function get_exclude_urls() {
489
  $list_exclude_urls = $this->get_option( 'exclude_urls' );
490
  $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
491
+ $destination_languages = $this->get_destination_languages( true );
492
+ $exclude_urls = array();
493
  if ( ! empty( $list_exclude_urls ) ) {
494
  foreach ( $list_exclude_urls as $item ) {
495
  if ( is_array( $item ) ) {
496
+ if ( ! empty( $item['excluded_languages'] ) ) {
497
+
498
+ if ( ! is_array( $item['excluded_languages'] ) ) {
499
+ continue;
500
+ }
501
+
502
+ $not_exclude = array_diff( $destination_languages, $item['excluded_languages'] );
503
+ if ( empty( $not_exclude ) ) {
504
+ $exclude_urls[] = $item;
505
+ } else {
506
+ continue;
507
+ }
508
+ }
509
  $regex = new Regex( $item['type'], $request_url_services->url_to_relative( $item['value'] ) );
510
  $exclude_urls[] = $regex->getRegex();
511
  } else {
513
  }
514
  }
515
  }
516
+ $exclude_urls[] = '/wp-login.php';
517
+ $exclude_urls[] = '/sitemaps_xsl.xsl';
518
+ $exclude_urls[] = '/sitemaps.xml';
519
+ $exclude_urls[] = '/wp-cron.php';
520
+ $exclude_urls[] = '/wp-comments-post.php';
521
+ $exclude_urls[] = '/ct_template'; // Compatibility Oxygen
522
+ $exclude_urls[] = '/main-sitemap.xsl'; // SEO by Rank Math
523
 
524
  $translate_amp = weglot_get_translate_amp_translation();
525
  if ( ! $translate_amp ) {
527
  }
528
 
529
  // array_map : Need only for those who use the filter
530
+ return apply_filters(
531
+ 'weglot_exclude_urls',
532
+ array_map(
533
+ function( $value ) use ( $request_url_services ) {
534
+ return $request_url_services->url_to_relative( $value );
535
+ },
536
+ $exclude_urls
537
+ )
538
+ );
539
+ }
540
+
541
+
542
+ /**
543
+ * @since 3.2.0
544
+ * @return array
545
+ */
546
+ public function get_exclude_urls_by_languages() {
547
+ $list_exclude_urls = $this->get_option( 'exclude_urls' );
548
+ $exclude_urls = array();
549
+
550
+ if ( ! empty( $list_exclude_urls ) ) {
551
+
552
+ $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
553
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
554
+
555
+ foreach ( $list_exclude_urls as $item ) {
556
+ if (
557
+ is_array( $item )
558
+ && ! empty( $item['excluded_languages'] )
559
+ && is_array( $item['excluded_languages'] )
560
+ ) {
561
+
562
+ $item['excluded_languages'] = array_map(
563
+ function ( $v ) use ( $language_code_rewrited ) {
564
+ return isset( $language_code_rewrited[ $v ] ) ? $language_code_rewrited[ $v ] : $v;
565
+ },
566
+ $item['excluded_languages']
567
+ );
568
+
569
+ $regex = new Regex( $item['type'], $request_url_services->url_to_relative( $item['value'] ) );
570
+ $exclude_urls[] = array(
571
+ 'value' => $regex->getRegex(),
572
+ 'excluded_languages' => $item['excluded_languages'],
573
+ );
574
+
575
+ } else {
576
+ continue;
577
+ }
578
+ }
579
+ }
580
+
581
+ apply_filters( 'weglot_exclude_urls_by_languages', $exclude_urls );
582
+
583
+ // Need only for those who use the filter
584
+ foreach ( $exclude_urls as $exclude_url ) {
585
+ $exclude_url['value'] = $request_url_services->url_to_relative( $exclude_url['value'] );
586
+ }
587
+
588
+ return $exclude_urls;
589
  }
590
 
591
  /**
623
  public function set_options( $options ) {
624
  $key = sprintf( '%s-%s', WEGLOT_SLUG, 'v3' );
625
  update_option( $key, $options );
626
+ wp_cache_delete( $key );
627
 
628
  return $this;
629
  }
653
  * @return any
654
  */
655
  public function get_option_by_key_v3( $key ) {
656
+ $options = $this->get_options_bdd_v3();
657
 
658
+ if ( ! array_key_exists( $key, $options ) ) {
659
  return null;
660
  }
661
 
src/services/class-parser-service-weglot.php CHANGED
@@ -2,10 +2,12 @@
2
 
3
  namespace WeglotWP\Services;
4
 
 
 
 
 
5
  use WeglotWP\Models\Hooks_Interface_Weglot;
6
  use WeglotWP\Helpers\Helper_API;
7
-
8
-
9
  use Weglot\Client\Client;
10
  use Weglot\Parser\Parser;
11
  use Weglot\Util\Url;
@@ -13,10 +15,6 @@ use Weglot\Util\Server;
13
  use Weglot\Parser\ConfigProvider\ServerConfigProvider;
14
  use Weglot\Parser\ConfigProvider\ConfigProviderInterface;
15
 
16
- if ( ! defined( 'ABSPATH' ) ) {
17
- exit;
18
- }
19
-
20
 
21
  /**
22
  * Parser abstraction
@@ -29,15 +27,15 @@ class Parser_Service_Weglot {
29
  * @since 2.0
30
  */
31
  public function __construct() {
32
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
33
 
34
  if ( '2' === WEGLOT_LIB_PARSER ) {
35
- $this->dom_listeners_services = weglot_get_service( 'Dom_Listeners_Service_Weglot' );
36
  } else {
37
- $this->dom_checkers_services = weglot_get_service( 'Dom_Checkers_Service_Weglot' );
38
  }
39
- $this->regex_checkers_services = weglot_get_service( 'Regex_Checkers_Service_Weglot' );
40
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
41
  }
42
 
43
  /**
@@ -51,9 +49,13 @@ class Parser_Service_Weglot {
51
  $translation_engine = 2;
52
  }
53
 
54
- $client = new Client( $api_key, $translation_engine, [
55
- 'host' => Helper_API::get_api_url(),
56
- ] );
 
 
 
 
57
  $client->getHttpClient()->addHeader( 'weglot-integration: WordPress Plugin' );
58
 
59
  return $client;
@@ -67,17 +69,20 @@ class Parser_Service_Weglot {
67
  public function get_parser() {
68
  $exclude_blocks = $this->option_services->get_exclude_blocks();
69
  if ( ! empty( $exclude_blocks ) ) {
70
- $exclude_blocks = array_map( function( $item ) {
71
- return $this->request_url_services->url_to_relative( $item );
72
- }, $exclude_blocks);
 
 
 
73
  }
74
 
75
- $config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
76
  if ( ! ( $config instanceof ConfigProviderInterface ) ) {
77
  $config = new ServerConfigProvider();
78
  }
79
 
80
- if( method_exists( $config, 'loadFromServer') ){
81
  $config->loadFromServer();
82
  }
83
 
@@ -87,7 +92,7 @@ class Parser_Service_Weglot {
87
  $listeners = $this->dom_listeners_services->get_dom_listeners();
88
  $parser = new Parser( $client, $config, $exclude_blocks, $listeners );
89
  } else {
90
- $parser = new Parser( $client, $config, $exclude_blocks );
91
  $parser->getDomCheckerProvider()->addCheckers( $this->dom_checkers_services->get_dom_checkers() );
92
  $parser->getRegexCheckerProvider()->addCheckers( $this->regex_checkers_services->get_regex_checkers() );
93
  $ignored_nodes = apply_filters( 'weglot_get_parser_ignored_nodes', $parser->getIgnoredNodesFormatter()->getIgnoredNodes() );
2
 
3
  namespace WeglotWP\Services;
4
 
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_API;
 
 
11
  use Weglot\Client\Client;
12
  use Weglot\Parser\Parser;
13
  use Weglot\Util\Url;
15
  use Weglot\Parser\ConfigProvider\ServerConfigProvider;
16
  use Weglot\Parser\ConfigProvider\ConfigProviderInterface;
17
 
 
 
 
 
18
 
19
  /**
20
  * Parser abstraction
27
  * @since 2.0
28
  */
29
  public function __construct() {
30
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
31
 
32
  if ( '2' === WEGLOT_LIB_PARSER ) {
33
+ $this->dom_listeners_services = weglot_get_service( 'Dom_Listeners_Service_Weglot' );
34
  } else {
35
+ $this->dom_checkers_services = weglot_get_service( 'Dom_Checkers_Service_Weglot' );
36
  }
37
+ $this->regex_checkers_services = weglot_get_service( 'Regex_Checkers_Service_Weglot' );
38
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
39
  }
40
 
41
  /**
49
  $translation_engine = 2;
50
  }
51
 
52
+ $client = new Client(
53
+ $api_key,
54
+ $translation_engine,
55
+ array(
56
+ 'host' => Helper_API::get_api_url(),
57
+ )
58
+ );
59
  $client->getHttpClient()->addHeader( 'weglot-integration: WordPress Plugin' );
60
 
61
  return $client;
69
  public function get_parser() {
70
  $exclude_blocks = $this->option_services->get_exclude_blocks();
71
  if ( ! empty( $exclude_blocks ) ) {
72
+ $exclude_blocks = array_map(
73
+ function( $item ) {
74
+ return $this->request_url_services->url_to_relative( $item );
75
+ },
76
+ $exclude_blocks
77
+ );
78
  }
79
 
80
+ $config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
81
  if ( ! ( $config instanceof ConfigProviderInterface ) ) {
82
  $config = new ServerConfigProvider();
83
  }
84
 
85
+ if ( method_exists( $config, 'loadFromServer' ) ) {
86
  $config->loadFromServer();
87
  }
88
 
92
  $listeners = $this->dom_listeners_services->get_dom_listeners();
93
  $parser = new Parser( $client, $config, $exclude_blocks, $listeners );
94
  } else {
95
+ $parser = new Parser( $client, $config, $exclude_blocks );
96
  $parser->getDomCheckerProvider()->addCheckers( $this->dom_checkers_services->get_dom_checkers() );
97
  $parser->getRegexCheckerProvider()->addCheckers( $this->regex_checkers_services->get_regex_checkers() );
98
  $ignored_nodes = apply_filters( 'weglot_get_parser_ignored_nodes', $parser->getIgnoredNodesFormatter()->getIgnoredNodes() );
src/services/class-private-language-service-weglot.php CHANGED
@@ -22,7 +22,7 @@ class Private_Language_Service_Weglot {
22
  * @since 2.3.0
23
  */
24
  public function __construct() {
25
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
26
  }
27
 
28
  /**
@@ -32,7 +32,7 @@ class Private_Language_Service_Weglot {
32
  * @return boolean
33
  */
34
  public function is_active_private_mode_for_lang( $key_lang ) {
35
- $private_mode_languages = $this->option_services->get_option( 'private_mode' );
36
 
37
  if ( ! is_array( $private_mode_languages ) ) {
38
  return false;
@@ -53,15 +53,15 @@ class Private_Language_Service_Weglot {
53
  }
54
 
55
  public function is_allowed_view_private() {
56
- return current_user_can( $this->role_private_mode ) || strpos(weglot_get_current_full_url(), 'weglot-private=1') !== false;
57
- }
58
 
59
  /**
60
  * @since 2.4.0
61
  * @return bool
62
  */
63
  public function private_mode_for_all_languages() {
64
- $private_mode_languages = $this->option_services->get_option( 'private_mode' );
65
  if ( $this->is_allowed_view_private() ) { // No check if admin
66
  return false;
67
  }
22
  * @since 2.3.0
23
  */
24
  public function __construct() {
25
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
26
  }
27
 
28
  /**
32
  * @return boolean
33
  */
34
  public function is_active_private_mode_for_lang( $key_lang ) {
35
+ $private_mode_languages = $this->option_services->get_option( 'private_mode' );
36
 
37
  if ( ! is_array( $private_mode_languages ) ) {
38
  return false;
53
  }
54
 
55
  public function is_allowed_view_private() {
56
+ return current_user_can( $this->role_private_mode ) || strpos( weglot_get_current_full_url(), 'weglot-private=1' ) !== false;
57
+ }
58
 
59
  /**
60
  * @since 2.4.0
61
  * @return bool
62
  */
63
  public function private_mode_for_all_languages() {
64
+ $private_mode_languages = $this->option_services->get_option( 'private_mode' );
65
  if ( $this->is_allowed_view_private() ) { // No check if admin
66
  return false;
67
  }
src/services/class-redirect-service-weglot.php CHANGED
@@ -33,9 +33,9 @@ class Redirect_Service_Weglot {
33
  * @since 2.0
34
  */
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
  /**
@@ -72,7 +72,7 @@ class Redirect_Service_Weglot {
72
  }
73
 
74
  if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { //phpcs:ignore
75
- $server_lang = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, apply_filters('weglot_number_of_character_for_language',2) );
76
  } else {
77
  if ( isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { // phpcs:ignore
78
  // Compatibility Cloudfare
@@ -94,18 +94,18 @@ class Redirect_Service_Weglot {
94
  exit();
95
  }
96
 
97
- if (
98
- !in_array( $server_lang, $destination_languages ) && // phpcs:ignore
99
- $server_lang !== weglot_get_original_language() &&
100
- weglot_get_original_language() === $this->request_url_services->get_current_language() &&
101
- ! $this->private_services->is_active_private_mode_for_lang( $server_lang ) &&
102
- $this->option_services->get_option('autoswitch_fallback') !== null
103
- ) {
104
- $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $this->option_services->get_option('autoswitch_fallback') ) );
105
- header( "Location: $url_auto_redirect", true, 302 );
106
- exit();
107
- }
108
- }
109
 
110
  /**
111
  * @since 2.0
33
  * @since 2.0
34
  */
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
  /**
72
  }
73
 
74
  if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { //phpcs:ignore
75
+ $server_lang = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, apply_filters( 'weglot_number_of_character_for_language', 2 ) );
76
  } else {
77
  if ( isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { // phpcs:ignore
78
  // Compatibility Cloudfare
94
  exit();
95
  }
96
 
97
+ if (
98
+ ! in_array( $server_lang, $destination_languages ) // phpcs:ignore
99
+ && $server_lang !== weglot_get_original_language()
100
+ && weglot_get_original_language() === $this->request_url_services->get_current_language()
101
+ && ! $this->private_services->is_active_private_mode_for_lang( $server_lang )
102
+ && $this->option_services->get_option( 'autoswitch_fallback' ) !== null
103
+ ) {
104
+ $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $this->option_services->get_option( 'autoswitch_fallback' ) ) );
105
+ header( "Location: $url_auto_redirect", true, 302 );
106
+ exit();
107
+ }
108
+ }
109
 
110
  /**
111
  * @since 2.0
src/services/class-regex-checkers-service-weglot.php CHANGED
@@ -10,6 +10,7 @@ use Weglot\Parser\Check\Regex\RegexChecker;
10
  use Weglot\Util\SourceType;
11
  use Weglot\Util\Text;
12
 
 
13
  /**
14
  * Dom Checkers
15
  *
@@ -18,12 +19,12 @@ use Weglot\Util\Text;
18
  */
19
  class Regex_Checkers_Service_Weglot {
20
 
21
- /**
22
- * @since 2.3.0
23
- */
24
- public function __construct() {
25
 
26
- }
27
 
28
  /**
29
  * @since 2.0
@@ -31,44 +32,43 @@ class Regex_Checkers_Service_Weglot {
31
  */
32
  public function get_regex_checkers() {
33
 
34
- $checkers = array();
35
-
36
- $other_words = apply_filters( 'weglot_words_translate', [] );
37
- foreach ($other_words as $other_word) {
38
- array_push($checkers, new RegexChecker( '#\b' . $other_word . '\b#u' , SourceType::SOURCE_TEXT , 0));
39
- }
40
 
 
 
 
 
41
 
42
- $thirds = array_diff( scandir( WEGLOT_DIR . '/src/third' ), [ '..', '.' ] );
43
- foreach ($thirds as $third) {
44
- $files = array_diff( scandir( WEGLOT_DIR . '/src/third/' . $third ), [ '..', '.' ] );
45
 
46
- foreach ($files as $file) {
47
- if (strpos($file, 'active.php') !== false) {
48
- $file = Text::removeFileExtension( $file );
49
- $file = str_replace( 'class-', '', $file );
50
- $file = implode( '_', array_map( 'ucfirst', explode( '-', $file ) ) );
51
- $service = weglot_get_service( $file );
52
- if(isset($service)) {
53
- $active = $service->is_active();
54
- if($active) {
55
- $regexDir = WEGLOT_DIR . '/src/third/' . $third . '/regexcheckers/';
56
- if(is_dir($regexDir)) {
57
- $regexFiles = array_diff( scandir( WEGLOT_DIR . '/src/third/' . $third . '/regexcheckers/' ), [ '..', '.' ] );
58
 
59
- foreach ($regexFiles as $regexFile) {
60
- $filename = Text::removeFileExtension( $regexFile );
61
- $filename = str_replace( 'class-', '', $filename );
62
- $filename = implode( '_', array_map( 'ucfirst', explode( '-', $filename ) ) );
63
- $class = '\\WeglotWP\\Third\\' . implode( '', array_map( 'ucfirst', explode( '-', $third ) ) ) . '\\Regexcheckers\\' . $filename;
64
- array_push($checkers, new RegexChecker( $class::REGEX , $class::TYPE, $class::VAR_NUMBER , $class::$KEYS));
65
- }
66
- }
67
- }
68
- }
69
- }
70
- }
71
- }
72
 
73
  return apply_filters( 'weglot_get_regex_checkers', $checkers );
74
  }
10
  use Weglot\Util\SourceType;
11
  use Weglot\Util\Text;
12
 
13
+
14
  /**
15
  * Dom Checkers
16
  *
19
  */
20
  class Regex_Checkers_Service_Weglot {
21
 
22
+ /**
23
+ * @since 2.3.0
24
+ */
25
+ public function __construct() {
26
 
27
+ }
28
 
29
  /**
30
  * @since 2.0
32
  */
33
  public function get_regex_checkers() {
34
 
35
+ $checkers = array();
 
 
 
 
 
36
 
37
+ $other_words = apply_filters( 'weglot_words_translate', array() );
38
+ foreach ( $other_words as $other_word ) {
39
+ array_push( $checkers, new RegexChecker( '#\b' . $other_word . '\b#u', SourceType::SOURCE_TEXT, 0 ) );
40
+ }
41
 
42
+ $thirds = array_diff( scandir( WEGLOT_DIR . '/src/third' ), array( '..', '.' ) );
43
+ foreach ( $thirds as $third ) {
44
+ $files = array_diff( scandir( WEGLOT_DIR . '/src/third/' . $third ), array( '..', '.' ) );
45
 
46
+ foreach ( $files as $file ) {
47
+ if ( strpos( $file, 'active.php' ) !== false ) {
48
+ $file = Text::removeFileExtension( $file );
49
+ $file = str_replace( 'class-', '', $file );
50
+ $file = implode( '_', array_map( 'ucfirst', explode( '-', $file ) ) );
51
+ $service = weglot_get_service( $file );
52
+ if ( isset( $service ) ) {
53
+ $active = $service->is_active();
54
+ if ( $active ) {
55
+ $regexDir = WEGLOT_DIR . '/src/third/' . $third . '/regexcheckers/';
56
+ if ( is_dir( $regexDir ) ) {
57
+ $regexFiles = array_diff( scandir( WEGLOT_DIR . '/src/third/' . $third . '/regexcheckers/' ), array( '..', '.' ) );
58
 
59
+ foreach ( $regexFiles as $regexFile ) {
60
+ $filename = Text::removeFileExtension( $regexFile );
61
+ $filename = str_replace( 'class-', '', $filename );
62
+ $filename = implode( '_', array_map( 'ucfirst', explode( '-', $filename ) ) );
63
+ $class = '\\WeglotWP\\Third\\' . implode( '', array_map( 'ucfirst', explode( '-', $third ) ) ) . '\\Regexcheckers\\' . $filename;
64
+ array_push( $checkers, new RegexChecker( $class::REGEX, $class::TYPE, $class::VAR_NUMBER, $class::$KEYS ) );
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
 
73
  return apply_filters( 'weglot_get_regex_checkers', $checkers );
74
  }
src/services/class-replace-link-service-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  /**
10
  * @since 2.0
11
  */
@@ -32,53 +33,68 @@ class Replace_Link_Service_Weglot {
32
  return $url;
33
  }
34
 
35
- $current_and_original = weglot_get_current_and_original_language();
36
- $custom_urls = $this->option_service->get_option( 'custom_urls' );
37
-
38
- $parsed_url = wp_parse_url( $url );
39
- $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
40
- $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
41
- $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
42
- $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
43
- $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
44
- $pass = ($user || $pass) ? "$pass@" : '';
45
- $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
46
- $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
47
- $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
48
-
49
- $current_language = $current_and_original['current'];
50
 
51
  if ( $current_and_original['current'] === $current_and_original['original'] ) {
52
  return $url;
53
- } else {
54
- $request_without_language = array_filter( explode( '/', $path ), 'strlen' );
55
- $index_entries = count( $request_without_language );
56
-
57
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
58
- $toTranslateLanguageIso = ($key = array_search($current_language,$language_code_rewrited)) ? $key:$current_language;
59
- if ( isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) && isset( $custom_urls[ $toTranslateLanguageIso ] ) ) {
60
- $slug_in_work = $request_without_language[ $index_entries ];
61
- $key_slug = array_search( $slug_in_work, $custom_urls[ $toTranslateLanguageIso ] ); //phpcs:ignore
62
- if ( false !== $key_slug && ! empty( $key_slug ) ) {
63
- $path = str_replace( $slug_in_work, $key_slug, $path );
64
- }
65
  }
66
 
67
- $url_translated = ( strlen( $path ) > 2 && strpos($path, "/$current_language/") !== false ) ?
68
- "$scheme$user$pass$host$port$path$query$fragment" : "$scheme$user$pass$host$port/$current_language$path$query$fragment";
69
-
70
- foreach ( array_reverse( $this->multisite_service->get_list_of_network_path() ) as $np ) {
71
- if ( strlen( $np ) > 2 && strpos( $url_translated, $np ) !== false ) {
72
- $url_translated = str_replace(
73
- str_replace( '//', '/', '/' . $current_language . $np . '/' ),
74
- str_replace( '//', '/', $np . '/' . $current_language . '/' ),
75
- $url_translated
76
- );
77
- }
 
 
78
  }
 
 
 
 
79
 
80
- return $url_translated;
 
 
 
 
 
 
 
81
  }
 
 
82
  }
83
 
84
  /**
@@ -119,8 +135,8 @@ class Replace_Link_Service_Weglot {
119
  * @return string
120
  */
121
  public function replace_datalink( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
122
- $current_language = weglot_get_current_language();
123
- $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-link=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-link=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
124
 
125
  return $translated_page;
126
  }
@@ -138,8 +154,8 @@ class Replace_Link_Service_Weglot {
138
  * @return string
139
  */
140
  public function replace_dataurl( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
141
- $current_language = weglot_get_current_language();
142
- $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-url=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-url=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
143
 
144
  return $translated_page;
145
  }
@@ -157,8 +173,8 @@ class Replace_Link_Service_Weglot {
157
  * @return string
158
  */
159
  public function replace_datacart( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
160
- $current_language = weglot_get_current_language();
161
- $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-cart-url=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-cart-url=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
162
 
163
  return $translated_page;
164
  }
@@ -176,8 +192,8 @@ class Replace_Link_Service_Weglot {
176
  * @return string
177
  */
178
  public function replace_form( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
179
- $current_language = weglot_get_current_language();
180
- $translated_page = preg_replace( '/<form' . preg_quote( $sometags, '/' ) . 'action=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<form ' . $sometags . 'action=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
181
 
182
  return $translated_page;
183
  }
@@ -195,8 +211,8 @@ class Replace_Link_Service_Weglot {
195
  * @return string
196
  */
197
  public function replace_canonical( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
198
- $current_language = weglot_get_current_language();
199
- $translated_page = preg_replace( '/<link rel="canonical"' . preg_quote( $sometags, '/' ) . 'href=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<link rel="canonical"' . $sometags . 'href=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
200
 
201
  return $translated_page;
202
  }
@@ -214,8 +230,8 @@ class Replace_Link_Service_Weglot {
214
  * @return string
215
  */
216
  public function replace_amp( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
217
- $current_language = weglot_get_current_language();
218
- $translated_page = preg_replace( '/<link rel="amphtml"' . preg_quote( $sometags, '/' ) . 'href=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<link rel="amphtml"' . $sometags . 'href=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
219
 
220
  return $translated_page;
221
  }
@@ -233,8 +249,8 @@ class Replace_Link_Service_Weglot {
233
  * @return string
234
  */
235
  public function replace_meta( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
236
- $current_language = weglot_get_current_language();
237
- $translated_page = preg_replace( '/<meta property="og:url"' . preg_quote( $sometags, '/' ) . 'content=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<meta property="og:url"' . $sometags . 'content=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
238
 
239
  return $translated_page;
240
  }
6
  exit;
7
  }
8
 
9
+
10
  /**
11
  * @since 2.0
12
  */
33
  return $url;
34
  }
35
 
36
+ $current_and_original = weglot_get_current_and_original_language();
37
+ $custom_urls = $this->option_service->get_option( 'custom_urls' );
38
+
39
+ $parsed_url = wp_parse_url( $url );
40
+ $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
41
+ $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
42
+ $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
43
+ $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
44
+ $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
45
+ $pass = ( $user || $pass ) ? "$pass@" : '';
46
+ $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
47
+ $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
48
+ $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
49
+ $current_language = $current_and_original['current'];
50
+ $current_destination_languages = weglot_get_current_destination_languages( $url );
51
 
52
  if ( $current_and_original['current'] === $current_and_original['original'] ) {
53
  return $url;
54
+ }
55
+
56
+ if ( ! in_array( $current_language, $current_destination_languages, true ) ) {
57
+
58
+ $default_language = apply_filters( 'weglot_replace_url_default_language', $current_and_original['original'] );
59
+
60
+ if ( $default_language === $current_and_original['original'] ) {
61
+ return $url;
62
+ }
63
+
64
+ if ( ! in_array( $default_language, $current_destination_languages, true ) ) {
65
+ return $url;
66
  }
67
 
68
+ $current_language = $default_language;
69
+ }
70
+
71
+ $request_without_language = array_filter( explode( '/', $path ), 'strlen' );
72
+ $index_entries = count( $request_without_language );
73
+
74
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
75
+ $to_translate_language_iso = ( $key = array_search( $current_language, $language_code_rewrited ) ) ? $key : $current_language;
76
+ if ( isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) && isset( $custom_urls[ $to_translate_language_iso ] ) ) {
77
+ $slug_in_work = $request_without_language[ $index_entries ];
78
+ $key_slug = array_search( $slug_in_work, $custom_urls[ $to_translate_language_iso ] ); //phpcs:ignore
79
+ if ( false !== $key_slug && ! empty( $key_slug ) ) {
80
+ $path = str_replace( $slug_in_work, $key_slug, $path );
81
  }
82
+ }
83
+
84
+ $url_translated = ( strlen( $path ) > 2 && strpos( $path, "/$current_language/" ) !== false ) ?
85
+ "$scheme$user$pass$host$port$path$query$fragment" : "$scheme$user$pass$host$port/$current_language$path$query$fragment";
86
 
87
+ foreach ( array_reverse( $this->multisite_service->get_list_of_network_path() ) as $np ) {
88
+ if ( strlen( $np ) > 2 && strpos( $url_translated, $np ) !== false ) {
89
+ $url_translated = str_replace(
90
+ str_replace( '//', '/', '/' . $current_language . $np . '/' ),
91
+ str_replace( '//', '/', $np . '/' . $current_language . '/' ),
92
+ $url_translated
93
+ );
94
+ }
95
  }
96
+
97
+ return $url_translated;
98
  }
99
 
100
  /**
135
  * @return string
136
  */
137
  public function replace_datalink( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
138
+ $current_language = weglot_get_current_language();
139
+ $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-link=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-link=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
140
 
141
  return $translated_page;
142
  }
154
  * @return string
155
  */
156
  public function replace_dataurl( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
157
+ $current_language = weglot_get_current_language();
158
+ $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-url=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-url=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
159
 
160
  return $translated_page;
161
  }
173
  * @return string
174
  */
175
  public function replace_datacart( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
176
+ $current_language = weglot_get_current_language();
177
+ $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-cart-url=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-cart-url=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
178
 
179
  return $translated_page;
180
  }
192
  * @return string
193
  */
194
  public function replace_form( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
195
+ $current_language = weglot_get_current_language();
196
+ $translated_page = preg_replace( '/<form' . preg_quote( $sometags, '/' ) . 'action=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<form ' . $sometags . 'action=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
197
 
198
  return $translated_page;
199
  }
211
  * @return string
212
  */
213
  public function replace_canonical( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
214
+ $current_language = weglot_get_current_language();
215
+ $translated_page = preg_replace( '/<link rel="canonical"' . preg_quote( $sometags, '/' ) . 'href=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<link rel="canonical"' . $sometags . 'href=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
216
 
217
  return $translated_page;
218
  }
230
  * @return string
231
  */
232
  public function replace_amp( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
233
+ $current_language = weglot_get_current_language();
234
+ $translated_page = preg_replace( '/<link rel="amphtml"' . preg_quote( $sometags, '/' ) . 'href=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<link rel="amphtml"' . $sometags . 'href=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
235
 
236
  return $translated_page;
237
  }
249
  * @return string
250
  */
251
  public function replace_meta( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
252
+ $current_language = weglot_get_current_language();
253
+ $translated_page = preg_replace( '/<meta property="og:url"' . preg_quote( $sometags, '/' ) . 'content=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<meta property="og:url"' . $sometags . 'content=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
254
 
255
  return $translated_page;
256
  }
src/services/class-replace-url-service-weglot.php CHANGED
@@ -10,6 +10,7 @@ use Weglot\Parser\Parser;
10
  use Weglot\Util\SourceType;
11
  use WeglotWP\Helpers\Helper_Replace_Url_Weglot;
12
 
 
13
  /**
14
  * Replace URL
15
  *
@@ -38,7 +39,7 @@ class Replace_Url_Service_Weglot {
38
  $dom = $this->modify_link( $value, $dom, $key );
39
  }
40
 
41
- $current_language = weglot_get_current_language();
42
  $language_code_rewrited = array_search( $current_language, apply_filters( 'weglot_language_code_replace', array() ) );
43
 
44
  if ( ! empty( $language_code_rewrited ) ) {
@@ -85,11 +86,11 @@ class Replace_Url_Service_Weglot {
85
  preg_match_all( $pattern, $translated_page, $out, PREG_PATTERN_ORDER );
86
  $count_out_0 = count( $out[0] );
87
  for ( $i = 0;$i < $count_out_0; $i++ ) {
88
- $sometags = ( isset( $out[1] ) ) ? $out[1][ $i ] : null;
89
- $quote1 = ( isset( $out[2] ) ) ? $out[2][ $i ] : null;
90
  $current_url = ( isset( $out[3] ) ) ? $out[3][ $i ] : null;
91
- $quote2 = ( isset( $out[4] ) ) ? $out[4][ $i ] : null;
92
- $sometags2 = ( isset( $out[5] ) ) ? $out[5][ $i ] : null;
93
 
94
  $length_link = apply_filters( 'weglot_length_replace_a', 1500 ); // Prevent error on long URL (preg_match_all Compilation failed: regular expression is too large at offset)
95
  if ( strlen( $current_url ) >= $length_link ) {
@@ -129,8 +130,8 @@ class Replace_Url_Service_Weglot {
129
  * @return string
130
  */
131
  public function check_link( $current_url, $sometags = null, $sometags2 = null ) {
132
- $admin_url = admin_url();
133
- $parsed_url = wp_parse_url( $current_url );
134
  $server_host = apply_filters( 'weglot_check_link_server_host', $_SERVER['HTTP_HOST'] ); //phpcs:ignore
135
 
136
  return (
@@ -162,6 +163,7 @@ class Replace_Url_Service_Weglot {
162
  'jpg',
163
  'jpeg',
164
  'png',
 
165
  'ppt',
166
  'pptx',
167
  'xls',
@@ -187,7 +189,7 @@ class Replace_Url_Service_Weglot {
187
  * @return boolean
188
  */
189
  public function ends_with( $haystack, $needle ) {
190
- $temp = strlen( $haystack );
191
  $len_needle = strlen( $needle );
192
 
193
  return '' === $needle ||
10
  use Weglot\Util\SourceType;
11
  use WeglotWP\Helpers\Helper_Replace_Url_Weglot;
12
 
13
+
14
  /**
15
  * Replace URL
16
  *
39
  $dom = $this->modify_link( $value, $dom, $key );
40
  }
41
 
42
+ $current_language = weglot_get_current_language();
43
  $language_code_rewrited = array_search( $current_language, apply_filters( 'weglot_language_code_replace', array() ) );
44
 
45
  if ( ! empty( $language_code_rewrited ) ) {
86
  preg_match_all( $pattern, $translated_page, $out, PREG_PATTERN_ORDER );
87
  $count_out_0 = count( $out[0] );
88
  for ( $i = 0;$i < $count_out_0; $i++ ) {
89
+ $sometags = ( isset( $out[1] ) ) ? $out[1][ $i ] : null;
90
+ $quote1 = ( isset( $out[2] ) ) ? $out[2][ $i ] : null;
91
  $current_url = ( isset( $out[3] ) ) ? $out[3][ $i ] : null;
92
+ $quote2 = ( isset( $out[4] ) ) ? $out[4][ $i ] : null;
93
+ $sometags2 = ( isset( $out[5] ) ) ? $out[5][ $i ] : null;
94
 
95
  $length_link = apply_filters( 'weglot_length_replace_a', 1500 ); // Prevent error on long URL (preg_match_all Compilation failed: regular expression is too large at offset)
96
  if ( strlen( $current_url ) >= $length_link ) {
130
  * @return string
131
  */
132
  public function check_link( $current_url, $sometags = null, $sometags2 = null ) {
133
+ $admin_url = admin_url();
134
+ $parsed_url = wp_parse_url( $current_url );
135
  $server_host = apply_filters( 'weglot_check_link_server_host', $_SERVER['HTTP_HOST'] ); //phpcs:ignore
136
 
137
  return (
163
  'jpg',
164
  'jpeg',
165
  'png',
166
+ 'svg',
167
  'ppt',
168
  'pptx',
169
  'xls',
189
  * @return boolean
190
  */
191
  public function ends_with( $haystack, $needle ) {
192
+ $temp = strlen( $haystack );
193
  $len_needle = strlen( $needle );
194
 
195
  return '' === $needle ||
src/services/class-request-url-service-weglot.php CHANGED
@@ -27,9 +27,9 @@ class Request_Url_Service_Weglot {
27
  * @since 2.0
28
  */
29
  public function __construct() {
30
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
31
- $this->amp_services = weglot_get_service( 'Amp_Service_Weglot' );
32
- $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
33
  }
34
 
35
  /**
@@ -61,7 +61,7 @@ class Request_Url_Service_Weglot {
61
  $destinations_language[] = $original_language;
62
  }
63
 
64
- $this->weglot_url = new Url(
65
  $this->get_full_url(),
66
  $original_language,
67
  $destinations_language,
@@ -121,7 +121,7 @@ class Request_Url_Service_Weglot {
121
  }
122
  }
123
 
124
- if( empty( $current_language ) ){
125
  return apply_filters( 'weglot_default_current_language_empty', 'en' );
126
  }
127
 
@@ -184,7 +184,7 @@ class Request_Url_Service_Weglot {
184
  * @return boolean
185
  */
186
  public function is_language_rtl( $code ) {
187
- $rtls = [ 'ar', 'he', 'fa' ];
188
  if ( in_array( $code, $rtls, true ) ) {
189
  return true;
190
  }
@@ -198,14 +198,14 @@ class Request_Url_Service_Weglot {
198
  * @return string|null
199
  */
200
  public function get_home_wordpress_directory() {
201
- $opt_siteurl = trim( get_option( 'siteurl' ), '/' );
202
- $opt_home = trim( get_option( 'home' ), '/' );
203
  if ( empty( $opt_siteurl ) || empty( $opt_home ) ) {
204
  return null;
205
  }
206
 
207
  if (
208
- ( substr( $opt_home, 0, 7 ) === 'http://' && strpos( substr( $opt_home, 7 ), '/' ) !== false) || ( substr( $opt_home, 0, 8 ) === 'https://' && strpos( substr( $opt_home, 8 ), '/' ) !== false ) ) {
209
  $parsed_url = parse_url( $opt_home ); // phpcs:ignore
210
  $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
211
  return $path;
@@ -222,31 +222,34 @@ class Request_Url_Service_Weglot {
222
  * @return boolean
223
  */
224
  public function is_eligible_url( $url ) {
225
- $destinations = weglot_get_destination_languages();
226
  if ( empty( $destinations ) ) {
227
  return true;
228
  }
229
 
230
- $url_relative = urldecode( $this->url_to_relative( $url ) );
231
-
232
  $exclude_urls_option = $this->option_services->get_exclude_urls();
 
 
 
233
 
234
- $path_without_language = array_filter( explode( '/', $url_relative ), 'strlen' );
235
- $index_entries = count( $path_without_language );
236
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
237
- $current_language = $this->get_current_language();
238
-
239
- $url_path_custom = null;
240
- if ( ! empty( $custom_urls ) && isset( $custom_urls[ $current_language ] ) && isset( $path_without_language[ $index_entries ] ) && isset( $custom_urls[ $current_language ][ $path_without_language[ $index_entries ] ] ) ) {
241
- $url_path_custom = get_site_url() . '/' . $custom_urls[ $current_language ][ $path_without_language[ $index_entries ] ] . '/';
242
  }
243
 
244
  $weglot_url = $this->create_url_object( $url );
245
  $weglot_url->setExcludedUrls( $exclude_urls_option );
 
246
  if ( ! $weglot_url->isTranslable() ) {
247
  return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
248
  }
249
 
 
 
 
 
250
  if ( $url_path_custom ) {
251
  $weglot_url = $this->create_url_object( $url_path_custom );
252
  $weglot_url->setExcludedUrls( $exclude_urls_option );
@@ -268,7 +271,6 @@ class Request_Url_Service_Weglot {
268
  return str_replace( '/', '\/', $str );
269
  }
270
 
271
-
272
  /**
273
  * @since 2.0
274
  * @param string $url
27
  * @since 2.0
28
  */
29
  public function __construct() {
30
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
31
+ $this->amp_services = weglot_get_service( 'Amp_Service_Weglot' );
32
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
33
  }
34
 
35
  /**
61
  $destinations_language[] = $original_language;
62
  }
63
 
64
+ $this->weglot_url = new Url(
65
  $this->get_full_url(),
66
  $original_language,
67
  $destinations_language,
121
  }
122
  }
123
 
124
+ if ( empty( $current_language ) ) {
125
  return apply_filters( 'weglot_default_current_language_empty', 'en' );
126
  }
127
 
184
  * @return boolean
185
  */
186
  public function is_language_rtl( $code ) {
187
+ $rtls = array( 'ar', 'he', 'fa' );
188
  if ( in_array( $code, $rtls, true ) ) {
189
  return true;
190
  }
198
  * @return string|null
199
  */
200
  public function get_home_wordpress_directory() {
201
+ $opt_siteurl = trim( get_option( 'siteurl' ), '/' );
202
+ $opt_home = trim( get_option( 'home' ), '/' );
203
  if ( empty( $opt_siteurl ) || empty( $opt_home ) ) {
204
  return null;
205
  }
206
 
207
  if (
208
+ ( substr( $opt_home, 0, 7 ) === 'http://' && strpos( substr( $opt_home, 7 ), '/' ) !== false ) || ( substr( $opt_home, 0, 8 ) === 'https://' && strpos( substr( $opt_home, 8 ), '/' ) !== false ) ) {
209
  $parsed_url = parse_url( $opt_home ); // phpcs:ignore
210
  $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
211
  return $path;
222
  * @return boolean
223
  */
224
  public function is_eligible_url( $url ) {
225
+ $destinations = weglot_get_current_destination_languages();
226
  if ( empty( $destinations ) ) {
227
  return true;
228
  }
229
 
230
+ $url_relative = urldecode( $this->url_to_relative( $url ) );
 
231
  $exclude_urls_option = $this->option_services->get_exclude_urls();
232
+ $custom_urls = $this->option_services->get_option( 'custom_urls' );
233
+ $current_language = $this->get_current_language();
234
+ $url_path_custom = null;
235
 
236
+ if ( isset( $custom_urls[ $current_language ] ) ) {
237
+ foreach ( $custom_urls[ $current_language ] as $key => $value ) {
238
+ $url_path_custom = str_replace( '/' . $key . '/', '/' . $value . '/', $url_relative );
239
+ }
 
 
 
 
240
  }
241
 
242
  $weglot_url = $this->create_url_object( $url );
243
  $weglot_url->setExcludedUrls( $exclude_urls_option );
244
+
245
  if ( ! $weglot_url->isTranslable() ) {
246
  return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
247
  }
248
 
249
+ if ( ! in_array( $current_language, array_merge( $destinations, array( weglot_get_original_language() ) ), true ) ) {
250
+ return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
251
+ }
252
+
253
  if ( $url_path_custom ) {
254
  $weglot_url = $this->create_url_object( $url_path_custom );
255
  $weglot_url->setExcludedUrls( $exclude_urls_option );
271
  return str_replace( '/', '\/', $str );
272
  }
273
 
 
274
  /**
275
  * @since 2.0
276
  * @param string $url
src/services/class-translate-service-weglot.php CHANGED
@@ -38,7 +38,7 @@ class Translate_Service_Weglot {
38
  $this->set_original_language( weglot_get_original_language() );
39
  $this->set_current_language( $this->request_url_services->get_current_language() );
40
 
41
- ob_start( [ $this, 'weglot_treat_page' ] );
42
  }
43
 
44
  /**
@@ -83,19 +83,18 @@ class Translate_Service_Weglot {
83
 
84
  try {
85
 
86
- $language_code_rewrited = apply_filters('weglot_language_code_replace' , array());
87
- $toTranslateLanguageIso = ($key = array_search($this->current_language,$language_code_rewrited)) ? $key:$this->current_language;
88
-
89
 
90
  switch ( $type ) {
91
  case 'json':
92
  $extraKeys = apply_filters( 'weglot_add_json_keys', array() );
93
- $translated_content = $parser->translate( $content, $this->original_language, $toTranslateLanguageIso, $extraKeys );
94
  $translated_content = json_encode( $this->replace_url_services->replace_link_in_json( json_decode( $translated_content, true ) ) );
95
  $translated_content = apply_filters( 'weglot_json_treat_page', $translated_content );
96
  return $translated_content;
97
  case 'html':
98
- $translated_content = $parser->translate( $content, $this->original_language, $toTranslateLanguageIso ); // phpcs:ignore
99
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
100
  return $this->weglot_render_dom( $translated_content );
101
  default:
38
  $this->set_original_language( weglot_get_original_language() );
39
  $this->set_current_language( $this->request_url_services->get_current_language() );
40
 
41
+ ob_start( array( $this, 'weglot_treat_page' ) );
42
  }
43
 
44
  /**
83
 
84
  try {
85
 
86
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
87
+ $to_translate_language_iso = ( $key = array_search( $this->current_language, $language_code_rewrited ) ) ? $key : $this->current_language;
 
88
 
89
  switch ( $type ) {
90
  case 'json':
91
  $extraKeys = apply_filters( 'weglot_add_json_keys', array() );
92
+ $translated_content = $parser->translate( $content, $this->original_language, $to_translate_language_iso, $extraKeys );
93
  $translated_content = json_encode( $this->replace_url_services->replace_link_in_json( json_decode( $translated_content, true ) ) );
94
  $translated_content = apply_filters( 'weglot_json_treat_page', $translated_content );
95
  return $translated_content;
96
  case 'html':
97
+ $translated_content = $parser->translate( $content, $this->original_language, $to_translate_language_iso ); // phpcs:ignore
98
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
99
  return $this->weglot_render_dom( $translated_content );
100
  default:
src/services/class-user-api-service-weglot.php CHANGED
@@ -8,6 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Helpers\Helper_API;
10
 
 
11
  /**
12
  * @since 2.0
13
  */
@@ -19,16 +20,16 @@ class User_Api_Service_Weglot {
19
  * @return array
20
  */
21
  public function get_plans() {
22
- return [
23
- 'starter_free' => [
24
- 'ids' => [ 2, 3 ],
25
  'limit_language' => 1,
26
- ],
27
- 'business' => [
28
- 'ids' => [ 4, 5 ],
29
  'limit_language' => 5,
30
- ],
31
- ];
32
  }
33
 
34
  /**
@@ -47,8 +48,8 @@ class User_Api_Service_Weglot {
47
  }
48
 
49
  try {
50
- $results = $this->do_request( Helper_API::get_api_url() . '/projects/owner?api_key=' . $api_key, null );
51
- $json = \json_decode( $results, true );
52
 
53
  if ( \json_last_error() !== JSON_ERROR_NONE ) {
54
  throw new \Exception( 'Unknown error with Weglot Api (0001) : ' . \json_last_error() );
@@ -71,9 +72,9 @@ class User_Api_Service_Weglot {
71
 
72
  throw new \Exception( 'Unknown error with Weglot Api (0002) : ' . $json );
73
  } catch ( \Exception $e ) {
74
- return [
75
  'not_exist' => false,
76
- ];
77
  }
78
  }
79
 
@@ -83,9 +84,9 @@ class User_Api_Service_Weglot {
83
  * @return int
84
  */
85
  public function get_limit_destination_language() {
86
- $user_info = $this->get_user_info();
87
- $plans = $this->get_plans();
88
- $limit = 1000;
89
  if (
90
  $user_info['plan_id'] <= 1 ||
91
  in_array( $user_info['plan_id'], $plans['starter_free']['ids'] ) // phpcs:ignore
@@ -120,9 +121,9 @@ class User_Api_Service_Weglot {
120
  'headers' => array(
121
  'Content-type' => 'application/json',
122
  ),
123
- 'body' => $payload,
124
- 'cookies' => array(),
125
- 'sslverify' => false,
126
  )
127
  );
128
  } else {
@@ -131,18 +132,18 @@ class User_Api_Service_Weglot {
131
  } else {
132
  $response = wp_remote_get( //phpcs:ignore
133
  $url,
134
- [
135
  'method' => 'GET',
136
  'timeout' => 45,
137
  'redirection' => 5,
138
  'blocking' => true,
139
- 'headers' => [
140
  'Content-type' => 'application/json',
141
- ],
142
- 'body' => null,
143
- 'cookies' => [],
144
- 'sslverify' => false,
145
- ]
146
  );
147
  }
148
 
8
 
9
  use WeglotWP\Helpers\Helper_API;
10
 
11
+
12
  /**
13
  * @since 2.0
14
  */
20
  * @return array
21
  */
22
  public function get_plans() {
23
+ return array(
24
+ 'starter_free' => array(
25
+ 'ids' => array( 2, 3 ),
26
  'limit_language' => 1,
27
+ ),
28
+ 'business' => array(
29
+ 'ids' => array( 4, 5 ),
30
  'limit_language' => 5,
31
+ ),
32
+ );
33
  }
34
 
35
  /**
48
  }
49
 
50
  try {
51
+ $results = $this->do_request( Helper_API::get_api_url() . '/projects/owner?api_key=' . $api_key, null );
52
+ $json = \json_decode( $results, true );
53
 
54
  if ( \json_last_error() !== JSON_ERROR_NONE ) {
55
  throw new \Exception( 'Unknown error with Weglot Api (0001) : ' . \json_last_error() );
72
 
73
  throw new \Exception( 'Unknown error with Weglot Api (0002) : ' . $json );
74
  } catch ( \Exception $e ) {
75
+ return array(
76
  'not_exist' => false,
77
+ );
78
  }
79
  }
80
 
84
  * @return int
85
  */
86
  public function get_limit_destination_language() {
87
+ $user_info = $this->get_user_info();
88
+ $plans = $this->get_plans();
89
+ $limit = 1000;
90
  if (
91
  $user_info['plan_id'] <= 1 ||
92
  in_array( $user_info['plan_id'], $plans['starter_free']['ids'] ) // phpcs:ignore
121
  'headers' => array(
122
  'Content-type' => 'application/json',
123
  ),
124
+ 'body' => $payload,
125
+ 'cookies' => array(),
126
+ 'sslverify' => false,
127
  )
128
  );
129
  } else {
132
  } else {
133
  $response = wp_remote_get( //phpcs:ignore
134
  $url,
135
+ array(
136
  'method' => 'GET',
137
  'timeout' => 45,
138
  'redirection' => 5,
139
  'blocking' => true,
140
+ 'headers' => array(
141
  'Content-type' => 'application/json',
142
+ ),
143
+ 'body' => null,
144
+ 'cookies' => array(),
145
+ 'sslverify' => false,
146
+ )
147
  );
148
  }
149
 
src/third/amp/class-amp-enqueue-weglot.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Flag_Type;
11
 
 
12
  /**
13
  * Amp_Enqueue_Weglot
14
  *
@@ -40,7 +41,7 @@ class Amp_Enqueue_Weglot implements Hooks_Interface_Weglot {
40
  return;
41
  }
42
 
43
- add_action( 'weglot_render_dom', [ $this, 'weglot_amp_css' ] );
44
  }
45
 
46
 
@@ -64,7 +65,7 @@ class Amp_Enqueue_Weglot implements Hooks_Interface_Weglot {
64
  $type_flags = weglot_get_option( 'type_flags' );
65
  $type_flags = Helper_Flag_Type::get_flag_number_with_type( $type_flags );
66
  $with_flags = weglot_get_option( 'with_flags' );
67
- $css = file_get_contents( WEGLOT_DIR_DIST . '/css/front-amp-css.css' ); //phpcs:ignore
68
  $css = str_replace( '../images/', WEGLOT_URL_DIST . '/images/', $css );
69
  $css .= $this->option_services->get_flag_css(); //phpcs:ignore
70
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Flag_Type;
11
 
12
+
13
  /**
14
  * Amp_Enqueue_Weglot
15
  *
41
  return;
42
  }
43
 
44
+ add_action( 'weglot_render_dom', array( $this, 'weglot_amp_css' ) );
45
  }
46
 
47
 
65
  $type_flags = weglot_get_option( 'type_flags' );
66
  $type_flags = Helper_Flag_Type::get_flag_number_with_type( $type_flags );
67
  $with_flags = weglot_get_option( 'with_flags' );
68
+ $css = file_get_contents( WEGLOT_DIR_DIST . '/css/front-amp-css.css' ); //phpcs:ignore
69
  $css = str_replace( '../images/', WEGLOT_URL_DIST . '/images/', $css );
70
  $css .= $this->option_services->get_flag_css(); //phpcs:ignore
71
 
src/third/cacheenabler/class-cache-enabler-active.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
@@ -26,7 +25,7 @@ class Cache_Enabler_Active implements Third_Active_Interface_Weglot {
26
  */
27
  public function is_active() {
28
  if ( ! function_exists( 'is_plugin_active' ) ) {
29
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
30
  }
31
 
32
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
25
  */
26
  public function is_active() {
27
  if ( ! function_exists( 'is_plugin_active' ) ) {
28
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
29
  }
30
 
31
  $active = true;
src/third/cacheenabler/class-cache-enabler-cache.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
 
12
  /**
13
  * Cache_Enabler_Cache
14
  *
@@ -36,8 +37,8 @@ class Cache_Enabler_Cache implements Hooks_Interface_Weglot {
36
  return;
37
  }
38
 
39
- add_filter( 'bypass_cache', [ $this, 'bypass_cache' ] );
40
- add_action( 'wp_head', [ $this, 'buffer_start' ] );
41
  }
42
 
43
  /**
@@ -58,7 +59,7 @@ class Cache_Enabler_Cache implements Hooks_Interface_Weglot {
58
  * @return void
59
  */
60
  public function buffer_start() {
61
- ob_start( [ $this, 'add_default_switcher' ] );
62
  }
63
 
64
  /**
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
+
13
  /**
14
  * Cache_Enabler_Cache
15
  *
37
  return;
38
  }
39
 
40
+ add_filter( 'bypass_cache', array( $this, 'bypass_cache' ) );
41
+ add_action( 'wp_head', array( $this, 'buffer_start' ) );
42
  }
43
 
44
  /**
59
  * @return void
60
  */
61
  public function buffer_start() {
62
+ ob_start( array( $this, 'add_default_switcher' ) );
63
  }
64
 
65
  /**
src/third/calderaforms/class-caldera-active.php CHANGED
@@ -6,11 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
13
-
14
  /**
15
  * Caldera_Active
16
  *
@@ -24,7 +22,7 @@ class Caldera_Active implements Third_Active_Interface_Weglot {
24
  */
25
  public function is_active() {
26
  if ( ! function_exists( 'is_plugin_active' ) ) {
27
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
28
  }
29
 
30
  $active = defined( 'CFCORE_VER' );
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
 
12
  /**
13
  * Caldera_Active
14
  *
22
  */
23
  public function is_active() {
24
  if ( ! function_exists( 'is_plugin_active' ) ) {
25
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
26
  }
27
 
28
  $active = defined( 'CFCORE_VER' );
src/third/calderaforms/class-caldera-i18n-inline.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
  use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
12
 
@@ -21,7 +20,7 @@ class Caldera_I18n_Inline implements Hooks_Interface_Weglot {
21
  * @return void
22
  */
23
  public function __construct() {
24
- $this->caldera_active_services = weglot_get_service( 'Caldera_Active' );
25
  }
26
 
27
  /**
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
 
20
  * @return void
21
  */
22
  public function __construct() {
23
+ $this->caldera_active_services = weglot_get_service( 'Caldera_Active' );
24
  }
25
 
26
  /**
src/third/calderaforms/regexcheckers/class-caldera-form-json-fields.php CHANGED
@@ -2,24 +2,24 @@
2
 
3
  namespace WeglotWP\Third\Calderaforms\Regexcheckers;
4
 
5
- use Weglot\Parser\Check\Regex\RegexChecker;
6
- use Weglot\Util\SourceType;
7
-
8
-
9
  if ( ! defined( 'ABSPATH' ) ) {
10
  exit;
11
  }
12
 
 
 
 
 
13
  /**
14
  * @since 2.0.7
15
  */
16
- class Caldera_Form_Json_Fields
17
- {
18
- const REGEX = '#CF_VALIDATOR_STRINGS = (.*?);#';
19
 
20
- const TYPE = SourceType::SOURCE_JSON;
21
 
22
- const VAR_NUMBER = 1;
23
 
24
- public static $KEYS = array( "defaultMessage","email","url","number","integer","digits","alphanum","required","pattern","min","max","range","minlength","maxlength","length","mincheck","maxcheck","check","equalto","notblank" );
25
  }
2
 
3
  namespace WeglotWP\Third\Calderaforms\Regexcheckers;
4
 
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Regex\RegexChecker;
10
+ use Weglot\Util\SourceType;
11
+
12
+
13
  /**
14
  * @since 2.0.7
15
  */
16
+ class Caldera_Form_Json_Fields {
17
+
18
+ const REGEX = '#CF_VALIDATOR_STRINGS = (.*?);#';
19
 
20
+ const TYPE = SourceType::SOURCE_JSON;
21
 
22
+ const VAR_NUMBER = 1;
23
 
24
+ public static $KEYS = array( 'defaultMessage', 'email', 'url', 'number', 'integer', 'digits', 'alphanum', 'required', 'pattern', 'min', 'max', 'range', 'minlength', 'maxlength', 'length', 'mincheck', 'maxcheck', 'check', 'equalto', 'notblank' );
25
  }
src/third/contactform7/class-contactform7-active.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
@@ -23,7 +22,7 @@ class Contactform7_Active implements Third_Active_Interface_Weglot {
23
  */
24
  public function is_active() {
25
  if ( ! function_exists( 'is_plugin_active' ) ) {
26
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
27
  }
28
 
29
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
22
  */
23
  public function is_active() {
24
  if ( ! function_exists( 'is_plugin_active' ) ) {
25
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
26
  }
27
 
28
  $active = true;
src/third/contactform7/class-contactform7-json-keys.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
 
12
  /**
13
  * Contactform7_Add_Json_Keys
14
  *
@@ -35,7 +36,7 @@ class Contactform7_Json_Keys implements Hooks_Interface_Weglot {
35
  return;
36
  }
37
 
38
- add_filter( 'weglot_add_json_keys', [ $this, 'weglot_contactform7_keys' ] );
39
  }
40
 
41
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
+
13
  /**
14
  * Contactform7_Add_Json_Keys
15
  *
36
  return;
37
  }
38
 
39
+ add_filter( 'weglot_add_json_keys', array( $this, 'weglot_contactform7_keys' ) );
40
  }
41
 
42
 
src/third/edd/class-edd-active.php CHANGED
@@ -6,11 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
13
-
14
  class Edd_Active implements Third_Active_Interface_Weglot {
15
 
16
  /**
@@ -21,7 +19,7 @@ class Edd_Active implements Third_Active_Interface_Weglot {
21
  */
22
  public function is_active() {
23
  if ( ! function_exists( 'is_plugin_active' ) ) {
24
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
25
  }
26
 
27
  if ( ! is_plugin_active( 'easy-digital-downloads/easy-digital-downloads.php' ) ) {
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
 
12
  class Edd_Active implements Third_Active_Interface_Weglot {
13
 
14
  /**
19
  */
20
  public function is_active() {
21
  if ( ! function_exists( 'is_plugin_active' ) ) {
22
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
23
  }
24
 
25
  if ( ! is_plugin_active( 'easy-digital-downloads/easy-digital-downloads.php' ) ) {
src/third/edd/class-edd-filter-urls.php CHANGED
@@ -9,13 +9,14 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
 
 
12
  class Edd_Filter_Urls implements Hooks_Interface_Weglot {
13
 
14
  /**
15
  * @return void
16
  */
17
  public function __construct() {
18
- $this->edd_active_services = weglot_get_service( 'Edd_Active' );
19
  }
20
 
21
  /**
@@ -28,9 +29,9 @@ class Edd_Filter_Urls implements Hooks_Interface_Weglot {
28
  return;
29
  }
30
 
31
- add_filter( 'edd_get_success_page_uri', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ] );
32
- add_filter( 'edd_get_checkout_uri', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ] );
33
  }
34
 
35
-
36
  }
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
 
12
+
13
  class Edd_Filter_Urls implements Hooks_Interface_Weglot {
14
 
15
  /**
16
  * @return void
17
  */
18
  public function __construct() {
19
+ $this->edd_active_services = weglot_get_service( 'Edd_Active' );
20
  }
21
 
22
  /**
29
  return;
30
  }
31
 
32
+ add_filter( 'edd_get_success_page_uri', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
33
+ add_filter( 'edd_get_checkout_uri', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
34
  }
35
 
36
+
37
  }
src/third/gravityforms/class-gf-active.php CHANGED
@@ -6,11 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
13
-
14
  /**
15
  * @since 3.0
16
  */
@@ -22,7 +20,7 @@ class Gf_Active implements Third_Active_Interface_Weglot {
22
  */
23
  public function is_active() {
24
  if ( ! function_exists( 'is_plugin_active' ) ) {
25
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
26
  }
27
 
28
  if ( ! is_plugin_active( 'gravityforms/gravityforms.php' ) ) {
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
 
12
  /**
13
  * @since 3.0
14
  */
20
  */
21
  public function is_active() {
22
  if ( ! function_exists( 'is_plugin_active' ) ) {
23
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
24
  }
25
 
26
  if ( ! is_plugin_active( 'gravityforms/gravityforms.php' ) ) {
src/third/gravityforms/class-gf-filter-urls.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
 
 
12
  /**
13
  * @since 3.0.0
14
  */
@@ -19,7 +20,7 @@ class GF_Filter_Urls implements Hooks_Interface_Weglot {
19
  * @return void
20
  */
21
  public function __construct() {
22
- $this->gf_active_services = weglot_get_service( 'Gf_Active' );
23
  }
24
 
25
  /**
@@ -33,7 +34,7 @@ class GF_Filter_Urls implements Hooks_Interface_Weglot {
33
  return;
34
  }
35
 
36
- add_filter( 'gform_confirmation', [ $this, 'weglot_gform_confirmation' ] );
37
  }
38
 
39
  /**
@@ -42,15 +43,15 @@ class GF_Filter_Urls implements Hooks_Interface_Weglot {
42
  * @return array
43
  */
44
  public function weglot_gform_confirmation( $data ) {
45
- if( ! is_array( $data ) ){
46
  return $data;
47
  }
48
 
49
- if( ! array_key_exists( 'redirect', $data ) ){
50
  return $data;
51
  }
52
 
53
- $data['redirect'] = Helper_Filter_Url_Weglot::filter_url_with_ajax($data['redirect']);
54
  return $data;
55
 
56
  }
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
 
12
+
13
  /**
14
  * @since 3.0.0
15
  */
20
  * @return void
21
  */
22
  public function __construct() {
23
+ $this->gf_active_services = weglot_get_service( 'Gf_Active' );
24
  }
25
 
26
  /**
34
  return;
35
  }
36
 
37
+ add_filter( 'gform_confirmation', array( $this, 'weglot_gform_confirmation' ) );
38
  }
39
 
40
  /**
43
  * @return array
44
  */
45
  public function weglot_gform_confirmation( $data ) {
46
+ if ( ! is_array( $data ) ) {
47
  return $data;
48
  }
49
 
50
+ if ( ! array_key_exists( 'redirect', $data ) ) {
51
  return $data;
52
  }
53
 
54
+ $data['redirect'] = Helper_Filter_Url_Weglot::filter_url_with_ajax( $data['redirect'] );
55
  return $data;
56
 
57
  }
src/third/mailoptin/class-mailoptin-active.php CHANGED
@@ -6,11 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
13
-
14
  /**
15
  * Mailoptin_Active
16
  *
@@ -26,7 +24,7 @@ class Mailoptin_Active implements Third_Active_Interface_Weglot {
26
  */
27
  public function is_active() {
28
  if ( ! function_exists( 'is_plugin_active' ) ) {
29
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
30
  }
31
 
32
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
 
12
  /**
13
  * Mailoptin_Active
14
  *
24
  */
25
  public function is_active() {
26
  if ( ! function_exists( 'is_plugin_active' ) ) {
27
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
28
  }
29
 
30
  $active = true;
src/third/mailoptin/regexcheckers/class-mailoptin-json.php CHANGED
@@ -2,26 +2,26 @@
2
 
3
  namespace WeglotWP\Third\MailOptin\Regexcheckers;
4
 
5
- use Weglot\Parser\Check\Regex\RegexChecker;
6
- use Weglot\Util\SourceType;
7
-
8
-
9
  if ( ! defined( 'ABSPATH' ) ) {
10
  exit;
11
  }
12
 
 
 
 
 
13
  /**
14
  * @since 3.1.2
15
  */
16
- class Mailoptin_Json
17
- {
18
- const REGEX = '#\<script type="text\/javascript">var .*_lightbox = (.*);\<\/script\>#';
19
 
20
- const TYPE = SourceType::SOURCE_JSON;
21
 
22
- const VAR_NUMBER = 1;
23
 
24
- public static $KEYS = array(
25
  'success_message',
26
  'unexpected_error',
27
  'email_missing_error',
2
 
3
  namespace WeglotWP\Third\MailOptin\Regexcheckers;
4
 
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Regex\RegexChecker;
10
+ use Weglot\Util\SourceType;
11
+
12
+
13
  /**
14
  * @since 3.1.2
15
  */
16
+ class Mailoptin_Json {
17
+
18
+ const REGEX = '#\<script type="text\/javascript">var .*_lightbox = (.*);\<\/script\>#';
19
 
20
+ const TYPE = SourceType::SOURCE_JSON;
21
 
22
+ const VAR_NUMBER = 1;
23
 
24
+ public static $KEYS = array(
25
  'success_message',
26
  'unexpected_error',
27
  'email_missing_error',
src/third/maintenance/class-maintenance-active.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
@@ -26,7 +25,7 @@ class Maintenance_Active implements Third_Active_Interface_Weglot {
26
  */
27
  public function is_active() {
28
  if ( ! function_exists( 'is_plugin_active' ) ) {
29
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
30
  }
31
 
32
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
25
  */
26
  public function is_active() {
27
  if ( ! function_exists( 'is_plugin_active' ) ) {
28
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
29
  }
30
 
31
  $active = true;
src/third/maintenance/class-maintenance-tracking.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
 
12
  /**
13
  * Maintenance_Tracking
14
  *
@@ -30,15 +31,15 @@ class Maintenance_Tracking implements Hooks_Interface_Weglot {
30
  * @return void
31
  */
32
  public function hooks() {
33
- if( ! Helper_Is_Admin::is_wp_admin()) {
34
- return;
35
- }
36
 
37
  if ( ! $this->maintenance_active_services->is_active() ) {
38
  return;
39
  }
40
 
41
- add_filter( 'weglot_tabs_admin_options_available', [ $this, 'weglot_maintenance_tracking' ] );
42
  }
43
 
44
 
@@ -48,7 +49,7 @@ class Maintenance_Tracking implements Hooks_Interface_Weglot {
48
  */
49
  public function weglot_maintenance_tracking( $options_available ) {
50
 
51
- if (isset($options_available['api_key_private']['description'])) {
52
 
53
  $register_link = 'https://dashboard.weglot.com/register-wordpress';
54
  $register_link_tracked = 'https://weglot.com/ad-track?origin=maintenance&redirectTo=https://dashboard.weglot.com/register-wordpress';
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
+
13
  /**
14
  * Maintenance_Tracking
15
  *
31
  * @return void
32
  */
33
  public function hooks() {
34
+ if ( ! Helper_Is_Admin::is_wp_admin() ) {
35
+ return;
36
+ }
37
 
38
  if ( ! $this->maintenance_active_services->is_active() ) {
39
  return;
40
  }
41
 
42
+ add_filter( 'weglot_tabs_admin_options_available', array( $this, 'weglot_maintenance_tracking' ) );
43
  }
44
 
45
 
49
  */
50
  public function weglot_maintenance_tracking( $options_available ) {
51
 
52
+ if ( isset( $options_available['api_key_private']['description'] ) ) {
53
 
54
  $register_link = 'https://dashboard.weglot.com/register-wordpress';
55
  $register_link_tracked = 'https://weglot.com/ad-track?origin=maintenance&redirectTo=https://dashboard.weglot.com/register-wordpress';
src/third/ninjaforms/class-ninja-active.php CHANGED
@@ -6,11 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
13
-
14
  /**
15
  * Ninja_Active_Weglot
16
  *
@@ -26,7 +24,7 @@ class Ninja_Active implements Third_Active_Interface_Weglot {
26
  */
27
  public function is_active() {
28
  if ( ! function_exists( 'is_plugin_active' ) ) {
29
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
30
  }
31
 
32
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
 
12
  /**
13
  * Ninja_Active_Weglot
14
  *
24
  */
25
  public function is_active() {
26
  if ( ! function_exists( 'is_plugin_active' ) ) {
27
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
28
  }
29
 
30
  $active = true;
src/third/ninjaforms/regexcheckers/class-ninja-form-json-fields.php CHANGED
@@ -2,24 +2,24 @@
2
 
3
  namespace WeglotWP\Third\Ninjaforms\Regexcheckers;
4
 
5
- use Weglot\Parser\Check\Regex\RegexChecker;
6
- use Weglot\Util\SourceType;
7
-
8
-
9
  if ( ! defined( 'ABSPATH' ) ) {
10
  exit;
11
  }
12
 
 
 
 
 
13
  /**
14
  * @since 2.0.7
15
  */
16
- class Ninja_Form_Json_Fields
17
- {
18
- const REGEX = '#form.fields=(.*?);nfForms#';
19
 
20
- const TYPE = SourceType::SOURCE_JSON;
21
 
22
- const VAR_NUMBER = 1;
23
 
24
- public static $KEYS = array( "label" , "help_text" , "value" );
25
  }
2
 
3
  namespace WeglotWP\Third\Ninjaforms\Regexcheckers;
4
 
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Regex\RegexChecker;
10
+ use Weglot\Util\SourceType;
11
+
12
+
13
  /**
14
  * @since 2.0.7
15
  */
16
+ class Ninja_Form_Json_Fields {
17
+
18
+ const REGEX = '#form.fields=(.*?);nfForms#';
19
 
20
+ const TYPE = SourceType::SOURCE_JSON;
21
 
22
+ const VAR_NUMBER = 1;
23
 
24
+ public static $KEYS = array( 'label', 'help_text', 'value' );
25
  }
src/third/ninjaforms/regexcheckers/class-ninja-form-json-nfi18n.php CHANGED
@@ -2,24 +2,24 @@
2
 
3
  namespace WeglotWP\Third\Ninjaforms\Regexcheckers;
4
 
5
- use Weglot\Parser\Check\Regex\RegexChecker;
6
- use Weglot\Util\SourceType;
7
-
8
-
9
  if ( ! defined( 'ABSPATH' ) ) {
10
  exit;
11
  }
12
 
 
 
 
 
13
  /**
14
  * @since 2.0.7
15
  */
16
- class Ninja_Form_Json_Nfi18n
17
- {
18
- const REGEX = '#nfi18n = (.*?);#';
19
 
20
- const TYPE = SourceType::SOURCE_JSON;
21
 
22
- const VAR_NUMBER = 1;
23
 
24
- public static $KEYS = array( "title" , "changeEmailErrorMsg" , "changeDateErrorMsg" , "confirmFieldErrorMsg" , "fieldNumberNumMinError" , "fieldNumberNumMaxError" , "fieldNumberIncrementBy" , "fieldTextareaRTEInsertLink" , "fieldTextareaRTEInsertMedia" , "fieldTextareaRTESelectAFile" , "formErrorsCorrectErrors" , "validateRequiredField" , "honeypotHoneypotError" , "fileUploadOldCodeFileUploadInProgress" , "previousMonth" , "nextMonth" , "fieldsMarkedRequired" , "fileUploadOldCodeFileUpload" );
25
  }
2
 
3
  namespace WeglotWP\Third\Ninjaforms\Regexcheckers;
4
 
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Regex\RegexChecker;
10
+ use Weglot\Util\SourceType;
11
+
12
+
13
  /**
14
  * @since 2.0.7
15
  */
16
+ class Ninja_Form_Json_Nfi18n {
17
+
18
+ const REGEX = '#nfi18n = (.*?);#';
19
 
20
+ const TYPE = SourceType::SOURCE_JSON;
21
 
22
+ const VAR_NUMBER = 1;
23
 
24
+ public static $KEYS = array( 'title', 'changeEmailErrorMsg', 'changeDateErrorMsg', 'confirmFieldErrorMsg', 'fieldNumberNumMinError', 'fieldNumberNumMaxError', 'fieldNumberIncrementBy', 'fieldTextareaRTEInsertLink', 'fieldTextareaRTEInsertMedia', 'fieldTextareaRTESelectAFile', 'formErrorsCorrectErrors', 'validateRequiredField', 'honeypotHoneypotError', 'fileUploadOldCodeFileUploadInProgress', 'previousMonth', 'nextMonth', 'fieldsMarkedRequired', 'fileUploadOldCodeFileUpload' );
25
  }
src/third/ninjaforms/regexcheckers/class-ninja-form-json-setting.php CHANGED
@@ -2,24 +2,24 @@
2
 
3
  namespace WeglotWP\Third\Ninjaforms\Regexcheckers;
4
 
5
- use Weglot\Parser\Check\Regex\RegexChecker;
6
- use Weglot\Util\SourceType;
7
-
8
-
9
  if ( ! defined( 'ABSPATH' ) ) {
10
  exit;
11
  }
12
 
 
 
 
 
13
  /**
14
  * @since 2.0.7
15
  */
16
- class Ninja_Form_Json_Setting
17
- {
18
- const REGEX = '#form.settings=(.*?);form#';
19
 
20
- const TYPE = SourceType::SOURCE_JSON;
21
 
22
- const VAR_NUMBER = 1;
23
 
24
- public static $KEYS = array( "title" , "changeEmailErrorMsg" , "changeDateErrorMsg" , "confirmFieldErrorMsg" , "fieldNumberNumMinError" , "fieldNumberNumMaxError" , "fieldNumberIncrementBy" , "fieldTextareaRTEInsertLink" , "fieldTextareaRTEInsertMedia" , "fieldTextareaRTESelectAFile" , "formErrorsCorrectErrors" , "validateRequiredField" , "honeypotHoneypotError" , "fileUploadOldCodeFileUploadInProgress" , "previousMonth" , "nextMonth" , "fieldsMarkedRequired");
25
  }
2
 
3
  namespace WeglotWP\Third\Ninjaforms\Regexcheckers;
4
 
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Regex\RegexChecker;
10
+ use Weglot\Util\SourceType;
11
+
12
+
13
  /**
14
  * @since 2.0.7
15
  */
16
+ class Ninja_Form_Json_Setting {
17
+
18
+ const REGEX = '#form.settings=(.*?);form#';
19
 
20
+ const TYPE = SourceType::SOURCE_JSON;
21
 
22
+ const VAR_NUMBER = 1;
23
 
24
+ public static $KEYS = array( 'title', 'changeEmailErrorMsg', 'changeDateErrorMsg', 'confirmFieldErrorMsg', 'fieldNumberNumMinError', 'fieldNumberNumMaxError', 'fieldNumberIncrementBy', 'fieldTextareaRTEInsertLink', 'fieldTextareaRTEInsertMedia', 'fieldTextareaRTESelectAFile', 'formErrorsCorrectErrors', 'validateRequiredField', 'honeypotHoneypotError', 'fileUploadOldCodeFileUploadInProgress', 'previousMonth', 'nextMonth', 'fieldsMarkedRequired' );
25
  }
src/third/theeventscalendar/class-theeventscalendar-active.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
@@ -23,7 +22,7 @@ class Theeventscalendar_Active implements Third_Active_Interface_Weglot {
23
  */
24
  public function is_active() {
25
  if ( ! function_exists( 'is_plugin_active' ) ) {
26
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
27
  }
28
 
29
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
22
  */
23
  public function is_active() {
24
  if ( ! function_exists( 'is_plugin_active' ) ) {
25
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
26
  }
27
 
28
  $active = true;
src/third/theeventscalendar/class-theeventscalendar-words.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
 
12
  /**
13
  * Theeventscalendar_Active
14
  *
@@ -35,7 +36,7 @@ class Theeventscalendar_Words implements Hooks_Interface_Weglot {
35
  return;
36
  }
37
 
38
- add_filter( 'weglot_words_translate', [ $this, 'weglot_theeventscalendar_words' ] );
39
  }
40
 
41
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
+
13
  /**
14
  * Theeventscalendar_Active
15
  *
36
  return;
37
  }
38
 
39
+ add_filter( 'weglot_words_translate', array( $this, 'weglot_theeventscalendar_words' ) );
40
  }
41
 
42
 
src/third/underconstructionpage/class-ucp-active.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
@@ -26,7 +25,7 @@ class Ucp_Active implements Third_Active_Interface_Weglot {
26
  */
27
  public function is_active() {
28
  if ( ! function_exists( 'is_plugin_active' ) ) {
29
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
30
  }
31
 
32
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
25
  */
26
  public function is_active() {
27
  if ( ! function_exists( 'is_plugin_active' ) ) {
28
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
29
  }
30
 
31
  $active = true;
src/third/underconstructionpage/class-ucp-tracking.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
 
12
  /**
13
  * UCP_Tracking
14
  *
@@ -30,15 +31,15 @@ class UCP_Tracking implements Hooks_Interface_Weglot {
30
  * @return void
31
  */
32
  public function hooks() {
33
- if( ! Helper_Is_Admin::is_wp_admin()) {
34
- return;
35
- }
36
 
37
  if ( ! $this->ucp_active_services->is_active() ) {
38
  return;
39
  }
40
 
41
- add_filter( 'weglot_tabs_admin_options_available', [ $this, 'weglot_ucp_tracking' ] );
42
  }
43
 
44
 
@@ -48,7 +49,7 @@ class UCP_Tracking implements Hooks_Interface_Weglot {
48
  */
49
  public function weglot_ucp_tracking( $options_available ) {
50
 
51
- if (isset($options_available['api_key_private']['description'])) {
52
 
53
  $register_link = 'https://dashboard.weglot.com/register-wordpress';
54
  $register_link_tracked = 'https://weglot.com/ad-track?origin=UCP&redirectTo=https://dashboard.weglot.com/register-wordpress';
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
+
13
  /**
14
  * UCP_Tracking
15
  *
31
  * @return void
32
  */
33
  public function hooks() {
34
+ if ( ! Helper_Is_Admin::is_wp_admin() ) {
35
+ return;
36
+ }
37
 
38
  if ( ! $this->ucp_active_services->is_active() ) {
39
  return;
40
  }
41
 
42
+ add_filter( 'weglot_tabs_admin_options_available', array( $this, 'weglot_ucp_tracking' ) );
43
  }
44
 
45
 
49
  */
50
  public function weglot_ucp_tracking( $options_available ) {
51
 
52
+ if ( isset( $options_available['api_key_private']['description'] ) ) {
53
 
54
  $register_link = 'https://dashboard.weglot.com/register-wordpress';
55
  $register_link_tracked = 'https://weglot.com/ad-track?origin=UCP&redirectTo=https://dashboard.weglot.com/register-wordpress';
src/third/woocommerce/class-wc-active.php CHANGED
@@ -6,11 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
13
-
14
  /**
15
  * Wc_Active
16
  *
@@ -26,7 +24,7 @@ class Wc_Active implements Third_Active_Interface_Weglot {
26
  */
27
  public function is_active() {
28
  if ( ! function_exists( 'is_plugin_active' ) ) {
29
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
30
  }
31
 
32
  if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
 
12
  /**
13
  * Wc_Active
14
  *
24
  */
25
  public function is_active() {
26
  if ( ! function_exists( 'is_plugin_active' ) ) {
27
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
28
  }
29
 
30
  if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
src/third/woocommerce/class-wc-cart-reload-weglot.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
 
12
  /**
13
  * WC_Cart_Reload_Weglot
14
  *
@@ -22,7 +23,7 @@ class WC_Cart_Reload_Weglot implements Hooks_Interface_Weglot {
22
  * @return void
23
  */
24
  public function __construct() {
25
- $this->wc_active_services = weglot_get_service( 'Wc_Active' );
26
  }
27
 
28
  /**
@@ -31,9 +32,9 @@ class WC_Cart_Reload_Weglot implements Hooks_Interface_Weglot {
31
  * @return void
32
  */
33
  public function hooks() {
34
- if( Helper_Is_Admin::is_wp_admin()) {
35
- return;
36
- }
37
 
38
  if ( ! $this->wc_active_services->is_active() ) {
39
  return;
@@ -45,18 +46,18 @@ class WC_Cart_Reload_Weglot implements Hooks_Interface_Weglot {
45
  return;
46
  }
47
 
48
- add_action( 'wp_footer', [ $this, 'weglot_wc_footer' ] );
49
  }
50
 
51
  /**
52
  * @since 2.4.0
53
  * @return void
54
  */
55
- public function weglot_wc_footer() {
56
  $click_selector = apply_filters( 'weglot_wc_reload_selector', '.weglot-lang a' );
57
  ?>
58
  <script>
59
- document.addEventListener('DOMContentLoaded', function () {
60
  if (!String.prototype.startsWith) {
61
  String.prototype.startsWith = function (searchString, position) {
62
  position = position || 0;
@@ -74,7 +75,7 @@ class WC_Cart_Reload_Weglot implements Hooks_Interface_Weglot {
74
  window.location.replace(href);
75
  })
76
  })
77
- </script>
78
  <?php
79
  }
80
  }
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
+
13
  /**
14
  * WC_Cart_Reload_Weglot
15
  *
23
  * @return void
24
  */
25
  public function __construct() {
26
+ $this->wc_active_services = weglot_get_service( 'Wc_Active' );
27
  }
28
 
29
  /**
32
  * @return void
33
  */
34
  public function hooks() {
35
+ if ( Helper_Is_Admin::is_wp_admin() ) {
36
+ return;
37
+ }
38
 
39
  if ( ! $this->wc_active_services->is_active() ) {
40
  return;
46
  return;
47
  }
48
 
49
+ add_action( 'wp_footer', array( $this, 'weglot_wc_footer' ) );
50
  }
51
 
52
  /**
53
  * @since 2.4.0
54
  * @return void
55
  */
56
+ public function weglot_wc_footer() {
57
  $click_selector = apply_filters( 'weglot_wc_reload_selector', '.weglot-lang a' );
58
  ?>
59
  <script>
60
+ document.addEventListener('DOMContentLoaded', function () {
61
  if (!String.prototype.startsWith) {
62
  String.prototype.startsWith = function (searchString, position) {
63
  position = position || 0;
75
  window.location.replace(href);
76
  })
77
  })
78
+ </script>
79
  <?php
80
  }
81
  }
src/third/woocommerce/class-wc-filter-urls-weglot.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
 
 
12
  /**
13
  * WC_Filter_Urls_Weglot
14
  *
@@ -21,10 +22,10 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
21
  * @return void
22
  */
23
  public function __construct() {
24
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
25
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
26
- $this->wc_active_services = weglot_get_service( 'Wc_Active' );
27
- $this->replace_url_services = weglot_get_service( 'Replace_Url_Service_Weglot' );
28
  }
29
 
30
  /**
@@ -39,24 +40,23 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
39
  return;
40
  }
41
 
42
- add_filter( 'woocommerce_get_cart_url', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ] );
43
- add_filter( 'woocommerce_get_checkout_url', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ] );
44
- add_filter( 'woocommerce_get_myaccount_page_permalink', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ] );
45
- add_filter( 'woocommerce_payment_successful_result', [ $this, 'woocommerce_filter_url_array' ] );
46
- add_filter( 'woocommerce_get_checkout_order_received_url', [ $this, 'woocommerce_filter_order_received_url' ] );
47
- add_action( 'woocommerce_reset_password_notification', [ $this, 'woocommerce_filter_reset_password' ], 999 );
48
 
49
- add_filter( 'woocommerce_login_redirect', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ] );
50
- add_filter( 'woocommerce_registration_redirect', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ] );
51
- add_filter( 'woocommerce_cart_item_permalink', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ] );
52
 
53
  /**
54
  * @since 2.6.0
55
  */
56
- add_filter( 'woocommerce_get_cart_page_permalink', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ] );
57
-
58
 
59
- add_filter( 'woocommerce_get_endpoint_url', [ $this, 'last_password_url_filter' ] , 10, 4);
60
  }
61
 
62
  /**
@@ -67,13 +67,13 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
67
  * @return string
68
  */
69
  public function woocommerce_filter_order_received_url( $url_filter ) {
70
- $current_and_original_language = weglot_get_current_and_original_language();
71
- $choose_current_language = $current_and_original_language['current'];
72
- $url = $this->request_url_services->create_url_object( $url_filter );
73
  if ( $current_and_original_language['current'] !== $current_and_original_language['original'] ) { // Not ajax
74
 
75
  if ( substr( get_option( 'permalink_structure' ), -1 ) !== '/' ) {
76
- return str_replace( '/?key', '?key', $url->getForLanguage( $choose_current_language ) );
77
  } else {
78
  return str_replace( '//?key', '/?key', str_replace( '?key', '/?key', $url->getForLanguage( $choose_current_language ) ) );
79
  }
@@ -93,22 +93,22 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
93
  return $url_filter;
94
  }
95
 
96
- public function last_password_url_filter($url, $endpoint, $value, $permalink) {
97
-
98
- if($endpoint === 'lost-password') {
99
- $current_headers = headers_list();
100
- foreach ($current_headers as $header) {
101
- if (strpos($header, 'wp-resetpass') !== false) {
102
- preg_match("#wp-resetpass-(.*?)=(.*?);#" , $header , $matchesName);
103
- preg_match("#path=(.*?);#" , $header , $matchesPath);
104
- if(isset($matchesName[0]) && isset($matchesPath[0]) && isset($matchesPath[1])) {
105
- setcookie( "wp-resetpass-". $matchesName[1], urldecode($matchesName[2]), 0, '/' . weglot_get_current_language() . $matchesPath[1], '' , is_ssl(), true );
106
- }
107
- }
108
- }
109
- }
110
- return $url;
111
- }
112
 
113
  /**
114
  * Filter array woocommerce filter with optional Ajax
@@ -125,15 +125,15 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
125
  } else {
126
  if ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
127
  // Ajax
128
- $url = $this->request_url_services->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
129
  $choose_current_language = $url->detectCurrentLanguage();
130
  $url = $this->request_url_services->create_url_object( $result['redirect'] );
131
  }
132
  }
133
  if ( $this->replace_url_services->check_link( $result['redirect'] ) ) { // We must not add language code if external link
134
- if(isset($url) && $url) {
135
- $result['redirect'] = $url->getForLanguage( $choose_current_language );
136
- }
137
  }
138
  return $result;
139
  }
@@ -144,7 +144,7 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
144
  * @since 2.0
145
  * @version 2.0.4
146
  * @param mixed $url
147
- * @return void
148
  */
149
  public function woocommerce_filter_reset_password( $url ) {
150
  $current_and_original_language = weglot_get_current_and_original_language();
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
 
12
+
13
  /**
14
  * WC_Filter_Urls_Weglot
15
  *
22
  * @return void
23
  */
24
  public function __construct() {
25
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
26
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
27
+ $this->wc_active_services = weglot_get_service( 'Wc_Active' );
28
+ $this->replace_url_services = weglot_get_service( 'Replace_Url_Service_Weglot' );
29
  }
30
 
31
  /**
40
  return;
41
  }
42
 
43
+ add_filter( 'woocommerce_get_cart_url', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ) );
44
+ add_filter( 'woocommerce_get_checkout_url', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ) );
45
+ add_filter( 'woocommerce_get_myaccount_page_permalink', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ) );
46
+ add_filter( 'woocommerce_payment_successful_result', array( $this, 'woocommerce_filter_url_array' ) );
47
+ add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'woocommerce_filter_order_received_url' ) );
48
+ add_action( 'woocommerce_reset_password_notification', array( $this, 'woocommerce_filter_reset_password' ), 999 );
49
 
50
+ add_filter( 'woocommerce_login_redirect', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ) );
51
+ add_filter( 'woocommerce_registration_redirect', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ) );
52
+ add_filter( 'woocommerce_cart_item_permalink', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
53
 
54
  /**
55
  * @since 2.6.0
56
  */
57
+ add_filter( 'woocommerce_get_cart_page_permalink', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
 
58
 
59
+ add_filter( 'woocommerce_get_endpoint_url', array( $this, 'last_password_url_filter' ), 10, 4 );
60
  }
61
 
62
  /**
67
  * @return string
68
  */
69
  public function woocommerce_filter_order_received_url( $url_filter ) {
70
+ $current_and_original_language = weglot_get_current_and_original_language();
71
+ $choose_current_language = $current_and_original_language['current'];
72
+ $url = $this->request_url_services->create_url_object( $url_filter );
73
  if ( $current_and_original_language['current'] !== $current_and_original_language['original'] ) { // Not ajax
74
 
75
  if ( substr( get_option( 'permalink_structure' ), -1 ) !== '/' ) {
76
+ return str_replace( '/?key', '?key', $url->getForLanguage( $choose_current_language ) );
77
  } else {
78
  return str_replace( '//?key', '/?key', str_replace( '?key', '/?key', $url->getForLanguage( $choose_current_language ) ) );
79
  }
93
  return $url_filter;
94
  }
95
 
96
+ public function last_password_url_filter( $url, $endpoint, $value, $permalink ) {
97
+
98
+ if ( $endpoint === 'lost-password' ) {
99
+ $current_headers = headers_list();
100
+ foreach ( $current_headers as $header ) {
101
+ if ( strpos( $header, 'wp-resetpass' ) !== false ) {
102
+ preg_match( '#wp-resetpass-(.*?)=(.*?);#', $header, $matchesName );
103
+ preg_match( '#path=(.*?);#', $header, $matchesPath );
104
+ if ( isset( $matchesName[0] ) && isset( $matchesPath[0] ) && isset( $matchesPath[1] ) ) {
105
+ setcookie( 'wp-resetpass-' . $matchesName[1], urldecode( $matchesName[2] ), 0, '/' . weglot_get_current_language() . $matchesPath[1], '', is_ssl(), true );
106
+ }
107
+ }
108
+ }
109
+ }
110
+ return $url;
111
+ }
112
 
113
  /**
114
  * Filter array woocommerce filter with optional Ajax
125
  } else {
126
  if ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
127
  // Ajax
128
+ $url = $this->request_url_services->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
129
  $choose_current_language = $url->detectCurrentLanguage();
130
  $url = $this->request_url_services->create_url_object( $result['redirect'] );
131
  }
132
  }
133
  if ( $this->replace_url_services->check_link( $result['redirect'] ) ) { // We must not add language code if external link
134
+ if ( isset( $url ) && $url ) {
135
+ $result['redirect'] = $url->getForLanguage( $choose_current_language );
136
+ }
137
  }
138
  return $result;
139
  }
144
  * @since 2.0
145
  * @version 2.0.4
146
  * @param mixed $url
147
+ * @return void
148
  */
149
  public function woocommerce_filter_reset_password( $url ) {
150
  $current_and_original_language = weglot_get_current_and_original_language();
src/third/woocommerce/class-wc-mail-weglot.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
 
12
  /**
13
  * WC_Mail_Weglot
14
  *
@@ -16,7 +17,6 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  */
17
  class WC_Mail_Weglot implements Hooks_Interface_Weglot {
18
 
19
-
20
  /**
21
  * @since 3.1.6
22
  * @return void
@@ -30,12 +30,12 @@ class WC_Mail_Weglot implements Hooks_Interface_Weglot {
30
  * @return void
31
  */
32
  public function hooks() {
33
- if ( ! $this->wc_active_services->is_active() || ! apply_filters( 'weglot_wooccommerce_translate_following_mail', false ) ) {
34
  return;
35
  }
36
 
37
- add_action( 'woocommerce_new_order', [ $this, 'save_language' ], 10, 1 );
38
- add_action( 'woocommerce_mail_callback_params', [ $this, 'translate_following_mail' ], 10, 2 );
39
  }
40
 
41
  /**
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
+
13
  /**
14
  * WC_Mail_Weglot
15
  *
17
  */
18
  class WC_Mail_Weglot implements Hooks_Interface_Weglot {
19
 
 
20
  /**
21
  * @since 3.1.6
22
  * @return void
30
  * @return void
31
  */
32
  public function hooks() {
33
+ if ( ! $this->wc_active_services->is_active() || ! apply_filters( 'weglot_woocommerce_translate_following_mail', true ) ) {
34
  return;
35
  }
36
 
37
+ add_action( 'woocommerce_new_order', array( $this, 'save_language' ), 10, 1 );
38
+ add_action( 'woocommerce_mail_callback_params', array( $this, 'translate_following_mail' ), 10, 2 );
39
  }
40
 
41
  /**
src/third/woocommerce/regexcheckers/class-wc-json-add-cart.php CHANGED
@@ -2,24 +2,24 @@
2
 
3
  namespace WeglotWP\Third\Woocommerce\Regexcheckers;
4
 
5
- use Weglot\Parser\Check\Regex\RegexChecker;
6
- use Weglot\Util\SourceType;
7
-
8
-
9
  if ( ! defined( 'ABSPATH' ) ) {
10
  exit;
11
  }
12
 
 
 
 
 
13
  /**
14
  * @since 2.0.7
15
  */
16
- class Wc_Json_Add_Cart
17
- {
18
- const REGEX = '#wc_add_to_cart_params = (.*?);#';
19
 
20
- const TYPE = SourceType::SOURCE_JSON;
21
 
22
- const VAR_NUMBER = 1;
23
 
24
- public static $KEYS = array( "i18n_view_cart" );
25
  }
2
 
3
  namespace WeglotWP\Third\Woocommerce\Regexcheckers;
4
 
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Regex\RegexChecker;
10
+ use Weglot\Util\SourceType;
11
+
12
+
13
  /**
14
  * @since 2.0.7
15
  */
16
+ class Wc_Json_Add_Cart {
17
+
18
+ const REGEX = '#wc_add_to_cart_params = (.*?);#';
19
 
20
+ const TYPE = SourceType::SOURCE_JSON;
21
 
22
+ const VAR_NUMBER = 1;
23
 
24
+ public static $KEYS = array( 'i18n_view_cart' );
25
  }
src/third/woocommerce/regexcheckers/class-wc-json-address.php CHANGED
@@ -2,24 +2,24 @@
2
 
3
  namespace WeglotWP\Third\Woocommerce\Regexcheckers;
4
 
5
- use Weglot\Parser\Check\Regex\RegexChecker;
6
- use Weglot\Util\SourceType;
7
-
8
-
9
  if ( ! defined( 'ABSPATH' ) ) {
10
  exit;
11
  }
12
 
 
 
 
 
13
  /**
14
  * @since 2.0.7
15
  */
16
- class Wc_Json_Address
17
- {
18
- const REGEX = '#wc_address_i18n_params = (.*?);#';
19
 
20
- const TYPE = SourceType::SOURCE_JSON;
21
 
22
- const VAR_NUMBER = 1;
23
 
24
- public static $KEYS = array( "label" , "placeholder" , "i18n_required_text" , "i18n_optional_text" );
25
  }
2
 
3
  namespace WeglotWP\Third\Woocommerce\Regexcheckers;
4
 
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
+ use Weglot\Parser\Check\Regex\RegexChecker;
10
+ use Weglot\Util\SourceType;
11
+
12
+
13
  /**
14
  * @since 2.0.7
15
  */
16
+ class Wc_Json_Address {
17
+
18
+ const REGEX = '#wc_address_i18n_params = (.*?);#';
19
 
20
+ const TYPE = SourceType::SOURCE_JSON;
21
 
22
+ const VAR_NUMBER = 1;
23
 
24
+ public static $KEYS = array( 'label', 'placeholder', 'i18n_required_text', 'i18n_optional_text' );
25
  }
src/third/wpforms/class-wpforms-active.php CHANGED
@@ -6,11 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
13
-
14
  /**
15
  * Wpforms_Active
16
  *
@@ -24,7 +22,7 @@ class Wpforms_Active implements Third_Active_Interface_Weglot {
24
  */
25
  public function is_active() {
26
  if ( ! function_exists( 'is_plugin_active' ) ) {
27
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
28
  }
29
 
30
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
 
12
  /**
13
  * Wpforms_Active
14
  *
22
  */
23
  public function is_active() {
24
  if ( ! function_exists( 'is_plugin_active' ) ) {
25
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
26
  }
27
 
28
  $active = true;
src/third/wpforms/regexcheckers/class-wp-form-json-setting.php CHANGED
@@ -2,24 +2,25 @@
2
 
3
  namespace WeglotWP\Third\Wpforms\Regexcheckers;
4
 
 
 
 
 
5
  use Weglot\Parser\Check\Regex\RegexChecker;
6
  use Weglot\Util\SourceType;
7
 
8
 
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
 
13
  /**
14
  * @since 2.0.7
15
  */
16
- class Wp_Form_Json_Setting
17
- {
18
- const REGEX = '#wpforms_settings = (.*?)(\n)(\/\* ]]> \*\/)#';
19
 
20
- const TYPE = SourceType::SOURCE_JSON;
21
 
22
- const VAR_NUMBER = 1;
23
 
24
- public static $KEYS = array( "val_required","val_url","val_email","val_email_suggestion","val_email_suggestion_title","val_number","val_confirm","val_fileextension","val_filesize","val_time12h","val_time24h","val_requiredpayment","val_creditcard","val_smart_phone","val_post_max_size","val_checklimit","val_checklimit");
25
  }
2
 
3
  namespace WeglotWP\Third\Wpforms\Regexcheckers;
4
 
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
  use Weglot\Parser\Check\Regex\RegexChecker;
10
  use Weglot\Util\SourceType;
11
 
12
 
 
 
 
13
 
14
  /**
15
  * @since 2.0.7
16
  */
17
+ class Wp_Form_Json_Setting {
18
+
19
+ const REGEX = '#wpforms_settings = (.*?)(\n)(\/\* ]]> \*\/)#';
20
 
21
+ const TYPE = SourceType::SOURCE_JSON;
22
 
23
+ const VAR_NUMBER = 1;
24
 
25
+ public static $KEYS = array( 'val_required', 'val_url', 'val_email', 'val_email_suggestion', 'val_email_suggestion_title', 'val_number', 'val_confirm', 'val_fileextension', 'val_filesize', 'val_time12h', 'val_time24h', 'val_requiredpayment', 'val_creditcard', 'val_smart_phone', 'val_post_max_size', 'val_checklimit', 'val_checklimit' );
26
  }
src/third/wpoptimize/class-wp-optimize-active.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
-
10
  use WeglotWP\Models\Third_Active_Interface_Weglot;
11
 
12
 
@@ -26,7 +25,7 @@ class Wp_Optimize_Active implements Third_Active_Interface_Weglot {
26
  */
27
  public function is_active() {
28
  if ( ! function_exists( 'is_plugin_active' ) ) {
29
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
30
  }
31
 
32
  $active = true;
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Third_Active_Interface_Weglot;
10
 
11
 
25
  */
26
  public function is_active() {
27
  if ( ! function_exists( 'is_plugin_active' ) ) {
28
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
29
  }
30
 
31
  $active = true;
src/third/wpoptimize/class-wp-optimize-cache.php CHANGED
@@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
 
12
  /**
13
  * Wp_Optimize_Cache
14
  *
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
+
13
  /**
14
  * Wp_Optimize_Cache
15
  *
src/third/yoast/class-redirect-handler-weglot.php CHANGED
@@ -4,6 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  }
6
 
 
7
  /**
8
  * Override Yoast Premium
9
  */
@@ -69,7 +70,7 @@ class Redirect_Handler_Weglot extends \WPSEO_Redirect_Handler {
69
  */
70
  protected function handle_normal_redirects( $request_url ) {
71
  // Setting the redirects.
72
- $redirects = $this->get_redirects( $this->normal_option_name );
73
  $this->redirects = $this->normalize_redirects( $redirects );
74
 
75
  // Trim the slashes, to match the variants of a request URL (Like: url, /url, /url/, url/).
@@ -82,7 +83,7 @@ class Redirect_Handler_Weglot extends \WPSEO_Redirect_Handler {
82
  if ( isset( $request_url[2] ) && '/' === $request_url[2] ) {
83
  $code_language = explode( '/', $request_url );
84
 
85
- $langs = weglot_get_languages_configured( 'code' );
86
 
87
  if ( ! in_array( $code_language[0], $langs ) ) { // phpcs:ignore
88
  //Default behavior Yoast
4
  exit;
5
  }
6
 
7
+
8
  /**
9
  * Override Yoast Premium
10
  */
70
  */
71
  protected function handle_normal_redirects( $request_url ) {
72
  // Setting the redirects.
73
+ $redirects = $this->get_redirects( $this->normal_option_name );
74
  $this->redirects = $this->normalize_redirects( $redirects );
75
 
76
  // Trim the slashes, to match the variants of a request URL (Like: url, /url, /url/, url/).
83
  if ( isset( $request_url[2] ) && '/' === $request_url[2] ) {
84
  $code_language = explode( '/', $request_url );
85
 
86
+ $langs = weglot_get_current_languages_configured( 'code' );
87
 
88
  if ( ! in_array( $code_language[0], $langs ) ) { // phpcs:ignore
89
  //Default behavior Yoast
src/widgets/class-widget-selector-weglot.php CHANGED
@@ -2,7 +2,9 @@
2
 
3
  namespace WeglotWP\Widgets;
4
 
5
- defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
 
 
6
 
7
 
8
  class Widget_Selector_Weglot extends \WP_Widget {
@@ -14,9 +16,9 @@ class Widget_Selector_Weglot extends \WP_Widget {
14
  parent::__construct(
15
  WEGLOT_SLUG,
16
  __( 'Weglot Translate', 'weglot' ),
17
- [
18
  'description' => __( 'Display Weglot selector in widget', 'weglot' ),
19
- ]
20
  );
21
  }
22
 
@@ -32,7 +34,7 @@ class Widget_Selector_Weglot extends \WP_Widget {
32
  if ( ! weglot_current_url_is_eligible() ) {
33
  return;
34
  }
35
- $title = (isset($instance['title'])) ? $instance['title'] : '';
36
  $title = apply_filters( 'widget_title', $title );
37
 
38
  $tt = ( ! empty( $title ) ) ? $args['before_title'] . $title . $args['after_title'] : '';
@@ -75,8 +77,8 @@ class Widget_Selector_Weglot extends \WP_Widget {
75
  * @return array Updated safe values to be saved.
76
  */
77
  public function update( $new_instance, $old_instance ) {
78
- $instance = [];
79
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( strip_tags( $new_instance['title'] ) ) : '';
80
  return $instance;
81
  }
82
  }
2
 
3
  namespace WeglotWP\Widgets;
4
 
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
 
9
 
10
  class Widget_Selector_Weglot extends \WP_Widget {
16
  parent::__construct(
17
  WEGLOT_SLUG,
18
  __( 'Weglot Translate', 'weglot' ),
19
+ array(
20
  'description' => __( 'Display Weglot selector in widget', 'weglot' ),
21
+ )
22
  );
23
  }
24
 
34
  if ( ! weglot_current_url_is_eligible() ) {
35
  return;
36
  }
37
+ $title = ( isset( $instance['title'] ) ) ? $instance['title'] : '';
38
  $title = apply_filters( 'widget_title', $title );
39
 
40
  $tt = ( ! empty( $title ) ) ? $args['before_title'] . $title . $args['after_title'] : '';
77
  * @return array Updated safe values to be saved.
78
  */
79
  public function update( $new_instance, $old_instance ) {
80
+ $instance = array();
81
+ $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( strip_tags( $new_instance['title'] ) ) : '';
82
  return $instance;
83
  }
84
  }
templates/admin/metaboxes/url-translate.php CHANGED
@@ -9,16 +9,16 @@ if ( ! defined( 'ABSPATH' ) ) {
9
 
10
  global $pagenow;
11
 
12
- if($pagenow === 'post-new.php'){
13
  esc_html_e( 'You must first create the page a first time before you can benefit from custom URLs', 'weglot' );
14
- }
15
- else{
16
 
17
- $languages_available = $this->language_services->get_languages_configured();
18
- $original_language = weglot_get_original_language();
19
- list( $permalink ) = get_sample_permalink( $post->ID );
20
- $display_link = str_replace( array( '%pagename%', '%postname%', home_url() ), '', $permalink );
21
- $display_link = implode( '/', array_filter( explode( '/', $display_link ), 'strlen' ) );
 
22
 
23
  if ( ! empty( $display_link ) && '/' !== $display_link[ strlen( $display_link ) - 1 ] ) {
24
  $display_link .= '/';
@@ -28,11 +28,16 @@ else{
28
  <input type="hidden" id="weglot_post_id" data-id="<?php echo esc_attr( $post->ID ); ?>" />
29
  <?php
30
  foreach ( $languages_available as $language ) {
31
- $code = $language->getIso639();
32
  if ( $code === $original_language ) {
33
  continue;
34
  }
35
 
 
 
 
 
 
36
  $post_name_weglot = $post->post_name;
37
  $post_name_input = '';
38
  if ( isset( $this->custom_urls[ $code ] ) ) {
@@ -42,13 +47,22 @@ else{
42
  } else {
43
  $post_name_input = $post_name_weglot;
44
  }
45
- } ?>
 
 
 
 
 
 
 
 
 
46
  <label for="lang-<?php echo esc_attr( $code ); ?>">
47
  <strong><?php echo esc_html( $language->getLocalName() ); ?></strong>
48
  </label>
49
  <div class="weglot_custom_url">
50
  <p class="weglot_custom_url--text_link">
51
- <?php echo esc_url( home_url() ); ?>/<?php echo esc_html( $code ); ?>/<?php echo esc_html( $display_link ); ?><span id="text-edit-<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $post_name_weglot ); ?></span>
52
  <input type="text" id="lang-<?php echo esc_attr( $code ); ?>" name="post_name_weglot[<?php echo esc_attr( $code ); ?>]" value="<?php echo esc_attr( $post_name_input ); ?>" style="display:none;"/>
53
 
54
  <button type="button" class="button button-small button-weglot-lang" data-lang="<?php echo esc_attr( $code ); ?>" aria-label="Edit permalink weglot"><span class="dashicons dashicons-edit"></span> <?php esc_html_e( 'Edit', 'weglot' ); ?></button>
@@ -56,7 +70,7 @@ else{
56
  <button type="button" class="button button-small button-weglot-lang-submit" data-lang="<?php echo esc_attr( $code ); ?>" style="display:none;"><?php esc_html_e( 'Ok', 'weglot' ); ?></button>
57
  </p>
58
  <p id="weglot_permalink_not_available_<?php echo esc_attr( $code ); ?>" class="weglot_text_error" style="display:none;"><?php esc_html_e( 'The permalink is not available.', 'weglot' ); ?></p>
59
- <a id="weglot_reset_custom_<?php echo esc_attr( $code ); ?>" data-lang="<?php echo esc_attr( $code ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>" href="<?php echo esc_attr( $post_name_weglot ) ; ?>" class="weglot_reset">
60
  <span class="dashicons dashicons-update-alt"></span> <?php esc_html_e( 'Reset custom url', 'weglot' ); ?>
61
  </a>
62
  </div>
@@ -64,4 +78,3 @@ else{
64
  <?php
65
  }
66
  }
67
-
9
 
10
  global $pagenow;
11
 
12
+ if ( 'post-new.php' === $pagenow ) {
13
  esc_html_e( 'You must first create the page a first time before you can benefit from custom URLs', 'weglot' );
14
+ } else {
 
15
 
16
+ $languages_available = weglot_get_current_languages_configured();
17
+ $original_language = weglot_get_original_language();
18
+ list( $permalink ) = get_sample_permalink( $post->ID );
19
+ $display_link = str_replace( array( '%pagename%', '%postname%', home_url() ), '', $permalink );
20
+ $display_link = implode( '/', array_filter( explode( '/', $display_link ), 'strlen' ) );
21
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
22
 
23
  if ( ! empty( $display_link ) && '/' !== $display_link[ strlen( $display_link ) - 1 ] ) {
24
  $display_link .= '/';
28
  <input type="hidden" id="weglot_post_id" data-id="<?php echo esc_attr( $post->ID ); ?>" />
29
  <?php
30
  foreach ( $languages_available as $language ) {
31
+ $code = $language->getIso639();
32
  if ( $code === $original_language ) {
33
  continue;
34
  }
35
 
36
+ $code_rewrited = $code;
37
+ if ( isset( $language_code_rewrited[ $code ] ) ) {
38
+ $code_rewrited = $language_code_rewrited[ $code ];
39
+ }
40
+
41
  $post_name_weglot = $post->post_name;
42
  $post_name_input = '';
43
  if ( isset( $this->custom_urls[ $code ] ) ) {
47
  } else {
48
  $post_name_input = $post_name_weglot;
49
  }
50
+ }
51
+
52
+ $display_link_translated = $display_link;
53
+
54
+ if ( isset( $this->custom_urls[ $code ] ) ) {
55
+ foreach ( $this->custom_urls[ $code ] as $key => $value ) {
56
+ $display_link_translated = str_replace( $value . '/', $key . '/', $display_link_translated );
57
+ }
58
+ }
59
+ ?>
60
  <label for="lang-<?php echo esc_attr( $code ); ?>">
61
  <strong><?php echo esc_html( $language->getLocalName() ); ?></strong>
62
  </label>
63
  <div class="weglot_custom_url">
64
  <p class="weglot_custom_url--text_link">
65
+ <?php echo esc_url( home_url() ); ?>/<?php echo esc_attr( $code_rewrited ); ?>/<?php echo esc_attr( $display_link_translated ); ?><span id="text-edit-<?php echo esc_attr( $code ); ?>"><?php echo esc_attr( $post_name_weglot ); ?></span>
66
  <input type="text" id="lang-<?php echo esc_attr( $code ); ?>" name="post_name_weglot[<?php echo esc_attr( $code ); ?>]" value="<?php echo esc_attr( $post_name_input ); ?>" style="display:none;"/>
67
 
68
  <button type="button" class="button button-small button-weglot-lang" data-lang="<?php echo esc_attr( $code ); ?>" aria-label="Edit permalink weglot"><span class="dashicons dashicons-edit"></span> <?php esc_html_e( 'Edit', 'weglot' ); ?></button>
70
  <button type="button" class="button button-small button-weglot-lang-submit" data-lang="<?php echo esc_attr( $code ); ?>" style="display:none;"><?php esc_html_e( 'Ok', 'weglot' ); ?></button>
71
  </p>
72
  <p id="weglot_permalink_not_available_<?php echo esc_attr( $code ); ?>" class="weglot_text_error" style="display:none;"><?php esc_html_e( 'The permalink is not available.', 'weglot' ); ?></p>
73
+ <a id="weglot_reset_custom_<?php echo esc_attr( $code ); ?>" data-lang="<?php echo esc_attr( $code ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>" href="<?php echo esc_attr( $post_name_weglot ); ?>" class="weglot_reset">
74
  <span class="dashicons dashicons-update-alt"></span> <?php esc_html_e( 'Reset custom url', 'weglot' ); ?>
75
  </a>
76
  </div>
78
  <?php
79
  }
80
  }
 
templates/admin/notices/no-configuration.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
 
7
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
8
 
 
9
  $tab_settings = Helper_Tabs_Admin_Weglot::get_full_tabs()[ Helper_Tabs_Admin_Weglot::SETTINGS ];
10
 
11
  ?>
6
 
7
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
8
 
9
+
10
  $tab_settings = Helper_Tabs_Admin_Weglot::get_full_tabs()[ Helper_Tabs_Admin_Weglot::SETTINGS ];
11
 
12
  ?>
templates/admin/pages/tabs/advanced.php CHANGED
@@ -77,46 +77,7 @@ $languages = array_values( $languages );
77
  <p class="sub-label"><?php echo esc_html( $options_available['exclude_urls']['description'] ); ?></p>
78
  </th>
79
  <td class="forminp forminp-text">
80
- <div id="container-<?php echo esc_attr( $options_available['exclude_urls']['key'] ); ?>">
81
- <?php
82
- if ( ! empty( $this->options[ $options_available['exclude_urls']['key'] ] ) ) :
83
- foreach ( $this->options[ $options_available['exclude_urls']['key'] ] as $key => $option ) :
84
- $type_option = RegexEnum::MATCH_REGEX;
85
- $value = $option;
86
- if ( is_array( $option ) ) {
87
- $type_option = $option['type'];
88
- $value = $option['value'];
89
- }
90
- ?>
91
- <div class="item-exclude">
92
- <select
93
- name="<?php echo esc_attr( sprintf( '%s[excluded_paths][%s][type]', WEGLOT_SLUG, $key ) ); ?>"
94
- >
95
- <?php foreach ( Helper_Excluded_Type::get_excluded_type() as $type ) : ?>
96
- <option
97
- value="<?php echo esc_attr( $type ); ?>"
98
- <?php echo selected( $type_option, $type ); ?>
99
- >
100
- <?php echo esc_html( Helper_Excluded_Type::get_label_type( $type ) ); ?>
101
- </option>
102
- <?php endforeach; ?>
103
- </select>
104
- <input
105
- type="text"
106
- placeholder="/my-awesome-url"
107
- name="<?php echo esc_attr( sprintf( '%s[excluded_paths][%s][value]', WEGLOT_SLUG, $key ) ); ?>"
108
- value="<?php echo esc_attr( $value ); ?>"
109
- >
110
- <button class="js-btn-remove js-btn-remove-exclude-url">
111
- <span class="dashicons dashicons-minus"></span>
112
- </button>
113
- </div>
114
- <?php
115
- endforeach;
116
- endif;
117
- ?>
118
- </div>
119
- <button id="js-add-exclude-url" class="btn btn-soft"><span class="dashicons dashicons-plus-alt"></span> <?php esc_html_e( 'Add an URL to exclude', 'weglot' ); ?></button>
120
  </td>
121
  </tr>
122
  <tr valign="top">
@@ -297,10 +258,10 @@ $languages = array_values( $languages );
297
  <template id="tpl-exclusion-block">
298
  <div class="item-exclude">
299
  <input
300
- type="text"
301
- placeholder=".my-class"
302
- name="<?php echo esc_attr( sprintf( '%s[excluded_blocks][][value]', WEGLOT_SLUG ) ); ?>"
303
- value=""
304
  >
305
  <button class="js-btn-remove js-btn-remove-exclude">
306
  <span class="dashicons dashicons-minus"></span>
77
  <p class="sub-label"><?php echo esc_html( $options_available['exclude_urls']['description'] ); ?></p>
78
  </th>
79
  <td class="forminp forminp-text">
80
+ <a class="btn btn-soft" href="https://dashboard.weglot.com/settings/exclusions" target="_blank"><span class="dashicons dashicons-admin-generic"></span> <?php esc_html_e( 'Manage URL to exclude', 'weglot' ); ?></a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  </td>
82
  </tr>
83
  <tr valign="top">
258
  <template id="tpl-exclusion-block">
259
  <div class="item-exclude">
260
  <input
261
+ type="text"
262
+ placeholder=".my-class"
263
+ name="<?php echo esc_attr( sprintf( '%s[excluded_blocks][][value]', WEGLOT_SLUG ) ); ?>"
264
+ value=""
265
  >
266
  <button class="js-btn-remove js-btn-remove-exclude">
267
  <span class="dashicons dashicons-minus"></span>
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit4d83de54192122360eb0aac62c095c48::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderIniteebc96ca5ff853865f9832c69d55f10d::getLoader();
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit4d83de54192122360eb0aac62c095c48
6
  {
7
  private static $loader;
8
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInit4d83de54192122360eb0aac62c095c48
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInit4d83de54192122360eb0aac62c095c48', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit4d83de54192122360eb0aac62c095c48', '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\ComposerStaticInit4d83de54192122360eb0aac62c095c48::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInit4d83de54192122360eb0aac62c095c48
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
- $includeFiles = Composer\Autoload\ComposerStaticInit4d83de54192122360eb0aac62c095c48::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
- composerRequire4d83de54192122360eb0aac62c095c48($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
- function composerRequire4d83de54192122360eb0aac62c095c48($fileIdentifier, $file)
64
  {
65
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderIniteebc96ca5ff853865f9832c69d55f10d
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderIniteebc96ca5ff853865f9832c69d55f10d', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderIniteebc96ca5ff853865f9832c69d55f10d', '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\ComposerStaticIniteebc96ca5ff853865f9832c69d55f10d::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\ComposerStaticIniteebc96ca5ff853865f9832c69d55f10d::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
+ composerRequireeebc96ca5ff853865f9832c69d55f10d($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
+ function composerRequireeebc96ca5ff853865f9832c69d55f10d($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 ComposerStaticInit4d83de54192122360eb0aac62c095c48
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
@@ -57,10 +57,10 @@ class ComposerStaticInit4d83de54192122360eb0aac62c095c48
57
  public static function getInitializer(ClassLoader $loader)
58
  {
59
  return \Closure::bind(function () use ($loader) {
60
- $loader->prefixLengthsPsr4 = ComposerStaticInit4d83de54192122360eb0aac62c095c48::$prefixLengthsPsr4;
61
- $loader->prefixDirsPsr4 = ComposerStaticInit4d83de54192122360eb0aac62c095c48::$prefixDirsPsr4;
62
- $loader->prefixesPsr0 = ComposerStaticInit4d83de54192122360eb0aac62c095c48::$prefixesPsr0;
63
- $loader->classMap = ComposerStaticInit4d83de54192122360eb0aac62c095c48::$classMap;
64
 
65
  }, null, ClassLoader::class);
66
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticIniteebc96ca5ff853865f9832c69d55f10d
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
57
  public static function getInitializer(ClassLoader $loader)
58
  {
59
  return \Closure::bind(function () use ($loader) {
60
+ $loader->prefixLengthsPsr4 = ComposerStaticIniteebc96ca5ff853865f9832c69d55f10d::$prefixLengthsPsr4;
61
+ $loader->prefixDirsPsr4 = ComposerStaticIniteebc96ca5ff853865f9832c69d55f10d::$prefixDirsPsr4;
62
+ $loader->prefixesPsr0 = ComposerStaticIniteebc96ca5ff853865f9832c69d55f10d::$prefixesPsr0;
63
+ $loader->classMap = ComposerStaticIniteebc96ca5ff853865f9832c69d55f10d::$classMap;
64
 
65
  }, null, ClassLoader::class);
66
  }
vendor/composer/installed.json CHANGED
@@ -133,23 +133,23 @@
133
  },
134
  {
135
  "name": "weglot/translation-definitions",
136
- "version": "v2.1.9",
137
- "version_normalized": "2.1.9.0",
138
  "source": {
139
  "type": "git",
140
  "url": "https://github.com/weglot/weglot-translation-definitions.git",
141
- "reference": "b93e636cf0544812f4dbf0e50683ce442c690954"
142
  },
143
  "dist": {
144
  "type": "zip",
145
- "url": "https://api.github.com/repos/weglot/weglot-translation-definitions/zipball/b93e636cf0544812f4dbf0e50683ce442c690954",
146
- "reference": "b93e636cf0544812f4dbf0e50683ce442c690954",
147
  "shasum": ""
148
  },
149
  "require": {
150
  "php": ">=5"
151
  },
152
- "time": "2020-04-09T16:21:17+00:00",
153
  "type": "library",
154
  "installation-source": "dist",
155
  "autoload": {
@@ -171,17 +171,17 @@
171
  },
172
  {
173
  "name": "weglot/weglot-php",
174
- "version": "1.0.5",
175
- "version_normalized": "1.0.5.0",
176
  "source": {
177
  "type": "git",
178
  "url": "https://github.com/weglot/weglot-php.git",
179
- "reference": "ac9544e015537967c630f9d05817462256853f55"
180
  },
181
  "dist": {
182
  "type": "zip",
183
- "url": "https://api.github.com/repos/weglot/weglot-php/zipball/ac9544e015537967c630f9d05817462256853f55",
184
- "reference": "ac9544e015537967c630f9d05817462256853f55",
185
  "shasum": ""
186
  },
187
  "require": {
@@ -194,7 +194,7 @@
194
  "codeception/codeception": "^2.4",
195
  "vlucas/phpdotenv": "^2.4"
196
  },
197
- "time": "2020-04-14T15:04:18+00:00",
198
  "type": "library",
199
  "installation-source": "dist",
200
  "autoload": {
133
  },
134
  {
135
  "name": "weglot/translation-definitions",
136
+ "version": "v2.1.10",
137
+ "version_normalized": "2.1.10.0",
138
  "source": {
139
  "type": "git",
140
  "url": "https://github.com/weglot/weglot-translation-definitions.git",
141
+ "reference": "e8f743d8e762600993edd4954f34b6068c13b83f"
142
  },
143
  "dist": {
144
  "type": "zip",
145
+ "url": "https://api.github.com/repos/weglot/weglot-translation-definitions/zipball/e8f743d8e762600993edd4954f34b6068c13b83f",
146
+ "reference": "e8f743d8e762600993edd4954f34b6068c13b83f",
147
  "shasum": ""
148
  },
149
  "require": {
150
  "php": ">=5"
151
  },
152
+ "time": "2020-06-08T15:20:54+00:00",
153
  "type": "library",
154
  "installation-source": "dist",
155
  "autoload": {
171
  },
172
  {
173
  "name": "weglot/weglot-php",
174
+ "version": "1.0.6",
175
+ "version_normalized": "1.0.6.0",
176
  "source": {
177
  "type": "git",
178
  "url": "https://github.com/weglot/weglot-php.git",
179
+ "reference": "81984950d616e0b67426dcb2f6297919e9aeb018"
180
  },
181
  "dist": {
182
  "type": "zip",
183
+ "url": "https://api.github.com/repos/weglot/weglot-php/zipball/81984950d616e0b67426dcb2f6297919e9aeb018",
184
+ "reference": "81984950d616e0b67426dcb2f6297919e9aeb018",
185
  "shasum": ""
186
  },
187
  "require": {
194
  "codeception/codeception": "^2.4",
195
  "vlucas/phpdotenv": "^2.4"
196
  },
197
+ "time": "2020-07-07T08:16:22+00:00",
198
  "type": "library",
199
  "installation-source": "dist",
200
  "autoload": {
vendor/weglot/translation-definitions/data/cases/cases-v3.json CHANGED
@@ -430,5 +430,15 @@
430
  "w": "test"
431
  }
432
  ]
 
 
 
 
 
 
 
 
 
 
433
  }
434
  ]
430
  "w": "test"
431
  }
432
  ]
433
+ },
434
+ {
435
+ "name": "Sentence with 2 comments",
436
+ "body": "<h2><!-- Comment 1 --><!--Comment2-->Hi there</h2>",
437
+ "expected": [
438
+ {
439
+ "t": 1,
440
+ "w": "Hi there"
441
+ }
442
+ ]
443
  }
444
  ]
vendor/weglot/weglot-php/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
 
7
  ## [Unreleased]
8
 
 
 
 
 
 
 
 
 
 
 
9
  ## [1.0.5] - 2020-04-14
10
  ### Added
11
  - Add callback mechanism on regex checker
6
 
7
  ## [Unreleased]
8
 
9
+ ## [1.0.6] - 2020-07-07
10
+ ### Added
11
+ - Add External links translation
12
+
13
+ ### Changed
14
+ - Simplify Regex for default regex checker (HTML template and JSON LD)
15
+
16
+ ### Fixed
17
+ - Fix a rare bug with comments inside nodes
18
+
19
  ## [1.0.5] - 2020-04-14
20
  ### Added
21
  - Add callback mechanism on regex checker
vendor/weglot/weglot-php/src/Client/Api/Enum/WordType.php CHANGED
@@ -20,11 +20,12 @@ abstract class WordType
20
  const IMG_ALT = 7;
21
  const PDF_HREF = 8;
22
  const TITLE = 9;
 
23
 
24
  /**
25
  * Only for internal use, if you have to add a value in this enum,
26
  * please increments the __MAX value.
27
  */
28
  const __MIN = 0;
29
- const __MAX = 9;
30
  }
20
  const IMG_ALT = 7;
21
  const PDF_HREF = 8;
22
  const TITLE = 9;
23
+ const EXTERNAL_LINK = 10;
24
 
25
  /**
26
  * Only for internal use, if you have to add a value in this enum,
27
  * please increments the __MAX value.
28
  */
29
  const __MIN = 0;
30
+ const __MAX = 10;
31
  }
vendor/weglot/weglot-php/src/Parser/Check/Dom/ExternalLinkHref.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Weglot\Parser\Check\Dom;
4
+
5
+ use Weglot\Client\Api\Enum\WordType;
6
+ use Weglot\Util\Text as TextUtil;
7
+
8
+ /**
9
+ * Class LinkHref
10
+ * @package Weglot\Parser\Check\Dom
11
+ */
12
+ class ExternalLinkHref extends AbstractDomChecker
13
+ {
14
+ /**
15
+ * {@inheritdoc}
16
+ */
17
+ const DOM = 'a';
18
+
19
+ /**
20
+ * {@inheritdoc}
21
+ */
22
+ const PROPERTY = 'href';
23
+
24
+ /**
25
+ * {@inheritdoc}
26
+ */
27
+ const WORD_TYPE = WordType::EXTERNAL_LINK;
28
+
29
+
30
+ /**
31
+ * {@inheritdoc}
32
+ */
33
+ protected function check()
34
+ {
35
+ $boolean = false;
36
+
37
+ $current_url = $this->node->href;
38
+ $parsed_url = parse_url( $current_url );
39
+ $server_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']:null;
40
+
41
+ if( isset($server_host) && isset($parsed_url['host']) && str_replace('www.', '', $parsed_url['host']) !== str_replace('www.', '', $server_host) ) {
42
+ return true;
43
+ }
44
+ else {
45
+ return false;
46
+ }
47
+
48
+ }
49
+ }
vendor/weglot/weglot-php/src/Parser/Check/DomCheckerProvider.php CHANGED
@@ -354,6 +354,7 @@ class DomCheckerProvider
354
  }
355
  }
356
  }
 
357
  }
358
  return $count;
359
  }
354
  }
355
  }
356
  }
357
+ $node->nodes = array_values($node->nodes);
358
  }
359
  return $count;
360
  }
vendor/weglot/weglot-php/src/Parser/Check/RegexCheckerProvider.php CHANGED
@@ -100,10 +100,10 @@ class RegexCheckerProvider
100
  protected function loadDefaultCheckers()
101
  {
102
  /* Add JSON LD checker */
103
- $this->addChecker(new RegexChecker("#<script type=('|\")application\/ld\+json('|\")([^\>]+?)?>((.|\n)*?)<\/script>#" , SourceType::SOURCE_JSON, 4 , array( "description" , "name" , "headline" , "articleSection" )));
104
 
105
  /* Add HTML template checker */
106
- $this->addChecker(new RegexChecker( "#<script type=('|\")text/html('|\")([^\>]+?)?>((.|\n)+?)<\/script>#" , SourceType::SOURCE_HTML, 4));
107
  }
108
 
109
  /**
100
  protected function loadDefaultCheckers()
101
  {
102
  /* Add JSON LD checker */
103
+ $this->addChecker(new RegexChecker("#<script type=('|\")application\/ld\+json('|\")([^\>]+?)?>(.*?)<\/script>#s" , SourceType::SOURCE_JSON, 4 , array( "description" , "name" , "headline" , "articleSection" )));
104
 
105
  /* Add HTML template checker */
106
+ $this->addChecker(new RegexChecker( "#<script type=('|\")text/html('|\")([^\>]+?)?>(.+?)<\/script>#s" , SourceType::SOURCE_HTML, 4));
107
  }
108
 
109
  /**
weglot-compatibility.php CHANGED
@@ -4,6 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  }
6
 
 
7
  /**
8
  * Compatibility WP < 4.7.0
9
  */
@@ -28,7 +29,7 @@ if ( ! function_exists( 'is_rest' ) ) {
28
  * Case #1: After WP_REST_Request initialisation
29
  * Case #2: Support "plain" permalink settings
30
  * Case #3: URL Path begins with wp-json/ (your REST prefix)
31
- * Also supports WP installations in subfolders
32
  *
33
  * @returns boolean
34
  * @author matzeeable
4
  exit;
5
  }
6
 
7
+
8
  /**
9
  * Compatibility WP < 4.7.0
10
  */
29
  * Case #1: After WP_REST_Request initialisation
30
  * Case #2: Support "plain" permalink settings
31
  * Case #3: URL Path begins with wp-json/ (your REST prefix)
32
+ * Also supports WP installations in subfolders
33
  *
34
  * @returns boolean
35
  * @author matzeeable
weglot-functions.php CHANGED
@@ -62,12 +62,21 @@ function weglot_get_destination_languages() {
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_languages();
71
  $original = weglot_get_original_language();
72
  array_unshift( $destinations, $original );
73
  return $destinations;
@@ -113,6 +122,16 @@ function weglot_get_languages_configured( $type = null ) {
113
  return Context_Weglot::weglot_get_context()->get_service( 'Language_Service_Weglot' )->get_languages_configured( $type );
114
  }
115
 
 
 
 
 
 
 
 
 
 
 
116
  /**
117
  * Get button selector HTML
118
  * @since 2.0
62
  return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_destination_languages();
63
  }
64
 
65
+ /**
66
+ * Get currrent destinations language with filters enable on specific URL
67
+ * @since 3.2.0
68
+ * @return array
69
+ */
70
+ function weglot_get_current_destination_languages( $current_url = null ) {
71
+ return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_current_destination_languages( $current_url );
72
+ }
73
+
74
  /**
75
  * @since 2.3.0
76
  * @return array
77
  */
78
  function weglot_get_all_languages_configured() {
79
+ $destinations = weglot_get_current_destination_languages();
80
  $original = weglot_get_original_language();
81
  array_unshift( $destinations, $original );
82
  return $destinations;
122
  return Context_Weglot::weglot_get_context()->get_service( 'Language_Service_Weglot' )->get_languages_configured( $type );
123
  }
124
 
125
+ /**
126
+ * @since 2.0
127
+ *
128
+ * @param null|string $type
129
+ * @return array
130
+ */
131
+ function weglot_get_current_languages_configured( $type = null ) {
132
+ return Context_Weglot::weglot_get_context()->get_service( 'Language_Service_Weglot' )->get_current_languages_configured( $type );
133
+ }
134
+
135
  /**
136
  * Get button selector HTML
137
  * @since 2.0
weglot.php CHANGED
@@ -7,7 +7,7 @@ Author: Weglot Translate team
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
- Version: 3.1.7
11
  */
12
 
13
  /**
@@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
22
  define( 'WEGLOT_NAME', 'Weglot' );
23
  define( 'WEGLOT_SLUG', 'weglot-translate' );
24
  define( 'WEGLOT_OPTION_GROUP', 'group-weglot-translate' );
25
- define( 'WEGLOT_VERSION', '3.1.7' );
26
  define( 'WEGLOT_PHP_MIN', '5.4' );
27
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
28
  define( 'WEGLOT_DIR', __DIR__ );
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
+ Version: 3.1.8
11
  */
12
 
13
  /**
22
  define( 'WEGLOT_NAME', 'Weglot' );
23
  define( 'WEGLOT_SLUG', 'weglot-translate' );
24
  define( 'WEGLOT_OPTION_GROUP', 'group-weglot-translate' );
25
+ define( 'WEGLOT_VERSION', '3.1.8' );
26
  define( 'WEGLOT_PHP_MIN', '5.4' );
27
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
28
  define( 'WEGLOT_DIR', __DIR__ );