Weglot Translate – Translate your WP website - Version 1.13

Version Description

(31/05/2018) = * Bugfix : Improve filter words_translate to prevent matching part of words * BugFix : Bug in parser when ignored node had an attribute * BugFix : character limit on chinese paragraphs * Add : Update message for version 2.0

Download this release

Release Info

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

Code changes from version 1.12.2 to 1.13

readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: translate,translation,language,multilingual,bilingual,international,locali
4
  Requires at least: 4.5
5
  Tested up to: 4.9
6
  Requires PHP: 5.3
7
- Stable tag: 1.12.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -152,6 +152,12 @@ See changelog for upgrade changes.
152
 
153
  == Changelog ==
154
 
 
 
 
 
 
 
155
  = 1.12.2 (04/05/2018) =
156
  * Bugfix : Limitation on the number of characters translated at the same time
157
 
4
  Requires at least: 4.5
5
  Tested up to: 4.9
6
  Requires PHP: 5.3
7
+ Stable tag: 1.13
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
152
 
153
  == Changelog ==
154
 
155
+ = 1.13 (31/05/2018) =
156
+ * Bugfix : Improve filter words_translate to prevent matching part of words
157
+ * BugFix : Bug in parser when ignored node had an attribute
158
+ * BugFix : character limit on chinese paragraphs
159
+ * Add : Update message for version 2.0
160
+
161
  = 1.12.2 (04/05/2018) =
162
  * Bugfix : Limitation on the number of characters translated at the same time
163
 
src/Client/WeglotClient.php CHANGED
@@ -13,8 +13,12 @@ class WeglotClient
13
  const API_BASE_OLD = 'https://weglot.com/api/';
14
  const NUMBER_MAX_CHARS = 500;
15
 
 
 
16
  public function __construct($key)
17
  {
 
 
18
  $this->api_key = $key;
19
 
20
  if ($this->api_key == null || mb_strlen($this->api_key) == 0) {
@@ -181,28 +185,15 @@ class WeglotClient
181
  return null;
182
  }
183
 
184
- public function ignoreNodes($dom)
185
- {
186
- $nodes_to_ignore = array(
187
- array('<strong>','</strong>'),
188
- array('<em>','</em>'),
189
- array('<abbr>','</abbr>'),
190
- array('<acronym>','</acronym>'),
191
- array('<b>','</b>'),
192
- array('<bdo>','</bdo>'),
193
- array('<big>','</big>'),
194
- array('<cite>','</cite>'),
195
- array('<kbd>','</kbd>'),
196
- array('<q>','</q>'),
197
- array('<small>','</small>'),
198
- array('<sub>','</sub>'),
199
- array('<sup>','</sup>'),
200
- );
201
 
 
 
202
 
203
- foreach ($nodes_to_ignore as $ignore) {
204
- $dom = str_replace($ignore[0], htmlentities($ignore[0]), $dom);
205
- $dom = str_replace($ignore[1], htmlentities($ignore[1]), $dom);
206
  }
207
 
208
  return $dom;
@@ -227,6 +218,8 @@ class WeglotClient
227
 
228
  $words = array();
229
  $nodes = array();
 
 
230
 
231
  $elements_to_check = array(
232
 
@@ -249,6 +242,15 @@ class WeglotClient
249
  ),
250
  ),
251
 
 
 
 
 
 
 
 
 
 
252
  'text'
253
  => array(
254
  array(
@@ -409,13 +411,13 @@ class WeglotClient
409
  $this->full_trim($row->$property) != '' &&
410
  ! $this->hasAncestorAttribute($row, 'data-wg-notranslate') &&
411
  $checkType &&
412
- (strlen($row->$property) <= self::NUMBER_MAX_CHARS || strpos($row->$property, ' ') !== false)
413
  ) {
414
  array_push(
415
  $words,
416
  array(
417
  't' => $t,
418
- 'w' => $row->$property,
419
  )
420
  );
421
  array_push(
@@ -432,7 +434,6 @@ class WeglotClient
432
  }
433
 
434
 
435
-
436
  $microData = array("description");
437
  $jsons = array();
438
  $nbJsonStrings = 0;
@@ -481,7 +482,8 @@ class WeglotClient
481
 
482
  if (!empty($otherWords) && is_array($otherWords)) {
483
  foreach ($otherWords as $otherWord) {
484
- if (strlen($otherWord) > self::NUMBER_MAX_CHARS && strpos($otherWord, ' ') === false) {
 
485
  continue;
486
  }
487
 
@@ -492,7 +494,7 @@ class WeglotClient
492
  }
493
  }
494
 
495
- $bot = $this->bot_detected();
496
  $parameters = array(
497
  'l_from' => $l_from,
498
  'l_to' => $l_to,
@@ -529,7 +531,7 @@ class WeglotClient
529
  if ($type == "meta_desc") {
530
  $currentNode['node']->$property = htmlspecialchars($translated_words[$i]);
531
  } else {
532
- $currentNode['node']->$property = $translated_words[$i];
533
  }
534
 
535
 
@@ -568,11 +570,13 @@ class WeglotClient
568
  return $dom;
569
  }
570
 
571
- $fromWords = array_slice($from_words, $index);
572
- $otherWordsTranslated = array_slice($translated_words, $index);
573
 
574
  foreach ($fromWords as $key => $fromWord) {
575
- $dom = str_replace($fromWord, $otherWordsTranslated[$key], $dom);
 
 
576
  }
577
 
578
  return $dom;
@@ -766,4 +770,43 @@ class WeglotClient
766
  {
767
  return trim($word, " \t\n\r\0\x0B\xA0�");
768
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
  }
13
  const API_BASE_OLD = 'https://weglot.com/api/';
14
  const NUMBER_MAX_CHARS = 500;
15
 
16
+ protected static $NODES_TO_IGNORE = null;
17
+
18
  public function __construct($key)
19
  {
20
+ self::$NODES_TO_IGNORE = array("strong","em","abbr","acronym","b","bdo","big","cite","kbd","q","small","sub","sup");
21
+
22
  $this->api_key = $key;
23
 
24
  if ($this->api_key == null || mb_strlen($this->api_key) == 0) {
185
  return null;
186
  }
187
 
188
+ function ignoreNodes($dom)
189
+ {
190
+ foreach (self::$NODES_TO_IGNORE as $n) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
+ $openRegex = "#<$n( [^>]*)?>#";
193
+ $closeRegex = "</$n>";
194
 
195
+ $dom = preg_replace($openRegex, "&lt;$n$1&gt;", $dom);
196
+ $dom = str_replace($closeRegex, "&lt;/$n&gt;", $dom);
 
197
  }
198
 
199
  return $dom;
218
 
219
  $words = array();
220
  $nodes = array();
221
+ $prewords = array();
222
+ $endwords = array();
223
 
224
  $elements_to_check = array(
225
 
242
  ),
243
  ),
244
 
245
+ 'meta[name="twitter:image"],meta[name="og:image"]'
246
+ => array(
247
+ array(
248
+ 'property' => 'content',
249
+ 't' => 6,
250
+ 'type' => 'meta_desc',
251
+ ),
252
+ ),
253
+
254
  'text'
255
  => array(
256
  array(
411
  $this->full_trim($row->$property) != '' &&
412
  ! $this->hasAncestorAttribute($row, 'data-wg-notranslate') &&
413
  $checkType &&
414
+ (strlen($row->$property) <= self::NUMBER_MAX_CHARS || preg_match('/\s|。|。|︒/u', $row->$property) )
415
  ) {
416
  array_push(
417
  $words,
418
  array(
419
  't' => $t,
420
+ 'w' => $this->trim_inline($row->$property,$prewords,$endwords),
421
  )
422
  );
423
  array_push(
434
  }
435
 
436
 
 
437
  $microData = array("description");
438
  $jsons = array();
439
  $nbJsonStrings = 0;
482
 
483
  if (!empty($otherWords) && is_array($otherWords)) {
484
  foreach ($otherWords as $otherWord) {
485
+
486
+ if (strlen($otherWord) > self::NUMBER_MAX_CHARS && preg_match('/\s|。|。|︒/u', $otherWord) == false) {
487
  continue;
488
  }
489
 
494
  }
495
  }
496
 
497
+ $bot = $this->bot_detected();
498
  $parameters = array(
499
  'l_from' => $l_from,
500
  'l_to' => $l_to,
531
  if ($type == "meta_desc") {
532
  $currentNode['node']->$property = htmlspecialchars($translated_words[$i]);
533
  } else {
534
+ $currentNode['node']->$property = $prewords[$i].$translated_words[$i].$endwords[$i];
535
  }
536
 
537
 
570
  return $dom;
571
  }
572
 
573
+ $fromWords = array_slice($from_words, $index+ $nbJsonStrings + $countWC18n);
574
+ $otherWordsTranslated = array_slice($translated_words, $index+ $nbJsonStrings + $countWC18n);
575
 
576
  foreach ($fromWords as $key => $fromWord) {
577
+ if(!preg_match("#<[^>\"']*".$fromWord."[^>\"']*>#",$dom)) {
578
+ $dom = preg_replace("#\b$fromWord\b#", $otherWordsTranslated[$key], $dom);
579
+ }
580
  }
581
 
582
  return $dom;
770
  {
771
  return trim($word, " \t\n\r\0\x0B\xA0�");
772
  }
773
+
774
+ /* This function remove inline tag when they are wrapping the whole sentence */
775
+ public function trim_inline($word,&$prewords,&$endwords) {
776
+
777
+ $word = html_entity_decode($word);
778
+
779
+ $all_nodes = "";
780
+ foreach (self::$NODES_TO_IGNORE as $n) {
781
+ $all_nodes .= $n.'|';
782
+ }
783
+ $all_nodes = trim($all_nodes,'|');
784
+
785
+ $regex = "#^<($all_nodes)>.*</($all_nodes)>$#";
786
+
787
+ $pre = "";
788
+ $suf = "";
789
+
790
+ while(preg_match($regex,$word,$matches)) {
791
+ $b = $matches[1];
792
+ $prefix = "<$b>";
793
+ $suffix = "</$b>";
794
+
795
+ if (substr($word, 0, strlen($prefix)) == $prefix) {
796
+ $word = substr($word, strlen($prefix));
797
+ $pre .= $prefix;
798
+ }
799
+
800
+ if (substr($word, strlen($word)-strlen($suffix), strlen($suffix)) == $suffix) {
801
+ $word = substr($word , 0 , strlen($word)-strlen($suffix));
802
+ $suf .=$suffix;
803
+ }
804
+ }
805
+
806
+ array_push($prewords,$pre);
807
+ array_push($endwords,$suf);
808
+
809
+ return $this->ignoreNodes($word);
810
+ }
811
+
812
  }
src/Helpers/WeglotLang.php CHANGED
@@ -136,8 +136,8 @@ abstract class WeglotLang
136
  'my' => __('Burmese', 'weglot'),
137
  'ca' => __('Catalan', 'weglot'),
138
  'ny' => __('Chichewa', 'weglot'),
139
- 'zh' => __('Chinese', 'weglot'),
140
- 'tw' => __('Chinese', 'weglot'),
141
  'co' => __('Corsican', 'weglot'),
142
  'hr' => __('Croatian', 'weglot'),
143
  'cs' => __('Czech', 'weglot'),
136
  'my' => __('Burmese', 'weglot'),
137
  'ca' => __('Catalan', 'weglot'),
138
  'ny' => __('Chichewa', 'weglot'),
139
+ 'zh' => __('Simplified Chinese', 'weglot'),
140
+ 'tw' => __('Traditional Chinese', 'weglot'),
141
  'co' => __('Corsican', 'weglot'),
142
  'hr' => __('Croatian', 'weglot'),
143
  'cs' => __('Czech', 'weglot'),
src/Helpers/WeglotUtils.php CHANGED
@@ -243,9 +243,9 @@ class WeglotUtils
243
 
244
  public static function is_AJAX_HTML($string)
245
  {
246
- $r = preg_match_all('/<(a|div|span|p|i|aside|input|textarea|select|h1|h2|h3|h4|meta|button|form|li|strong|ul)/',
247
  $string, $m, PREG_PATTERN_ORDER);
248
- if (isset($string[0]) && $string[0] != '{' && $r && $r >= 2) {
249
  return true;
250
  } else {
251
  return false;
243
 
244
  public static function is_AJAX_HTML($string)
245
  {
246
+ $r = preg_match_all('/<(a|div|span|p|i|aside|input|textarea|select|h1|h2|h3|h4|meta|button|form|li|strong|ul|option)/',
247
  $string, $m, PREG_PATTERN_ORDER);
248
+ if (isset($string[0]) && $string[0] != '{' && $r && $r >= 1) {
249
  return true;
250
  } else {
251
  return false;
weglot.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * @package Weglot
4
- * @version 1.12.2
5
  */
6
 
7
  /*
@@ -12,7 +12,7 @@ Author: Weglot Translate team
12
  Author URI: https://weglot.com/
13
  Text Domain: weglot
14
  Domain Path: /languages/
15
- Version: 1.12.2
16
  */
17
 
18
  /*
@@ -41,7 +41,7 @@ if (! defined('ABSPATH')) {
41
  }
42
 
43
 
44
- define('WEGLOT_VERSION', '1.12.2');
45
  define('WEGLOT_DIR', dirname(__FILE__));
46
  define('WEGLOT_BNAME', plugin_basename(__FILE__));
47
  define('WEGLOT_DIRURL', plugin_dir_url(__FILE__));
@@ -124,8 +124,7 @@ class Weglot
124
 
125
  WeglotContext::setOriginalLanguage(get_option('original_l'));
126
  WeglotContext::setDestinationLanguage(get_option('destination_l'));
127
- WeglotContext::setHomeDirectory(WeglotUrl::getHomeDirectory());
128
-
129
 
130
  $this->request_uri = $this->getRequestUri(WeglotContext::getHomeDirectory());
131
  $this->network_paths = $this->getListOfNetworkPath();
@@ -230,6 +229,168 @@ class Weglot
230
  } else {
231
  add_shortcode('weglot_switcher', array( $this, 'wg_switcher_creation_empty' ));
232
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  }
234
 
235
 
@@ -802,7 +963,8 @@ class Weglot
802
  $l,
803
  'OPTION'
804
  );
805
- $this->modifyLink('/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/', $translatedPage, $l, 'LINK');
 
806
  $this->modifyLink('/<meta property="og:url"(.*?)?content=(\"|\')([^\s\>]+?)(\"|\')/', $translatedPage, $l, 'META');
807
 
808
 
@@ -941,7 +1103,7 @@ class Weglot
941
  ) . $quote2 . '$2>', $translatedPage);
942
  }
943
 
944
- public function replaceLINK(
945
  &$translatedPage,
946
  $current_url,
947
  $l,
@@ -957,6 +1119,22 @@ class Weglot
957
  $quote2, '/') . '/', '<link rel="canonical"' . $sometags . 'href=' . $quote1 . $this->replaceUrl($current_url, $l) . $quote2, $translatedPage);
958
  }
959
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
960
  public function replaceMETA(
961
  &$translatedPage,
962
  $current_url,
@@ -1104,12 +1282,21 @@ class Weglot
1104
 
1105
  public function getRequestUri($home_dir)
1106
  {
1107
- if ($home_dir) {
1108
- return str_replace($home_dir, '', $_SERVER['REQUEST_URI']);
1109
  } else {
1110
  return $_SERVER['REQUEST_URI'];
1111
  }
1112
  }
 
 
 
 
 
 
 
 
 
1113
  public function getLangFromUrl($request_uri)
1114
  {
1115
  $l = null;
@@ -1188,7 +1375,10 @@ class Weglot
1188
 
1189
  foreach ($destEx as $d) {
1190
  if ($d != $current) {
1191
- $link = ($d != WeglotContext::getOriginalLanguage()) ? $this->replaceUrl(WeglotContext::getHomeDirectory().$this->request_uri_no_language, $d) : WeglotContext::getHomeDirectory().$this->request_uri_no_language;
 
 
 
1192
  if ($link == WeglotContext::getHomeDirectory().'/' && get_option('wg_auto_switch') == 'on') {
1193
  $link = $link . '?no_lredirect=true';
1194
  }
1
  <?php
2
  /**
3
  * @package Weglot
4
+ * @version 1.13
5
  */
6
 
7
  /*
12
  Author URI: https://weglot.com/
13
  Text Domain: weglot
14
  Domain Path: /languages/
15
+ Version: 1.13
16
  */
17
 
18
  /*
41
  }
42
 
43
 
44
+ define('WEGLOT_VERSION', '1.13');
45
  define('WEGLOT_DIR', dirname(__FILE__));
46
  define('WEGLOT_BNAME', plugin_basename(__FILE__));
47
  define('WEGLOT_DIRURL', plugin_dir_url(__FILE__));
124
 
125
  WeglotContext::setOriginalLanguage(get_option('original_l'));
126
  WeglotContext::setDestinationLanguage(get_option('destination_l'));
127
+ WeglotContext::setHomeDirectory($this->getHomeDirectory());
 
128
 
129
  $this->request_uri = $this->getRequestUri(WeglotContext::getHomeDirectory());
130
  $this->network_paths = $this->getListOfNetworkPath();
229
  } else {
230
  add_shortcode('weglot_switcher', array( $this, 'wg_switcher_creation_empty' ));
231
  }
232
+
233
+ add_action( 'in_plugin_update_message-weglot/weglot.php', array($this, 'weglot_updates_message'), 10, 2 );
234
+
235
+ }
236
+
237
+ public function weglot_updates_message_requirements(){
238
+ $php_version = phpversion();
239
+ $wp_version = get_bloginfo('version');
240
+
241
+
242
+ if (version_compare($php_version, '5.4', '<') || version_compare($wp_version, '4.5.0', '<')) {
243
+ ?>
244
+ <script>
245
+ var $ = jQuery
246
+ $(document).ready(function(){
247
+ $("#weglot-update a.update-link").addClass('button-disabled')
248
+ })
249
+ </script>
250
+ <div class="weglot_plugin_upgrade-sub-title"><?php _e('Requirements : ','weglot'); ?></div>
251
+ <table class=" plugin-details-table" cellspacing="0">
252
+ <tbody>
253
+ <?php if (version_compare($wp_version, '4.5.0', '<')){
254
+ ?>
255
+ <tr>
256
+ <th><?php esc_html_e('WordPress Version :', 'weglot'); ?></th>
257
+ <td>4.5.0</td>
258
+ </tr>
259
+ <?php
260
+ } ?>
261
+ <?php if (version_compare($php_version, '5.4', '<')){ ?>
262
+ <tr>
263
+ <th><?php esc_html_e('PHP Version', 'weglot'); ?></th>
264
+ <td>5.4</td>
265
+ </tr>
266
+ <?php
267
+ } ?>
268
+ </tbody>
269
+ </table>
270
+ <?php
271
+ }
272
+ }
273
+
274
+ public function get_messageJ14(){
275
+
276
+ ?>
277
+ <p>
278
+ <?php _e("<strong style='color:red;'>Warning!</strong> The new version 2.0 of Weglot involves many changes.", 'weglot'); ?>
279
+ </p>
280
+ <?php
281
+ _e("We are still in <span class='weglot-warning-beta'>beta</span> on this new version.", 'weglot');
282
+ ?><br /><?php
283
+ _e("Remember to <strong>take your precautions</strong> during this update and do not hesitate to <strong>make a backup</strong>. Otherwise you can wait for the 2.1 that will be more stable.", 'weglot');
284
+
285
+ }
286
+
287
+ public function get_messageJ30(){
288
+ ?>
289
+ <p>
290
+ <?php _e("<strong style='color:red;'>Warning!</strong> The new version 2 of Weglot involves many changes.", 'weglot'); ?>
291
+ </p>
292
+ <?php
293
+ _e("If you see a problem, please report to <strong>support@weglot.com</strong>", 'weglot');
294
+
295
+ }
296
+
297
+ public function get_messageJ60(){
298
+ _e("<strong>Heads up!</strong> The new version 2 of Weglot involves many changes.", 'weglot');
299
+ }
300
+
301
+ public function weglot_updates_message( $plugin_data, $new_plugin_data ) {
302
+ // Get next version.
303
+ if (isset($new_plugin_data->new_version)) {
304
+ $remote_version = $new_plugin_data->new_version;
305
+ }
306
+
307
+ if (! isset($remote_version)) {
308
+ return;
309
+ }
310
+
311
+ if(!preg_match('/^2\.(\d+)(\.(\d+))?/', $remote_version)){
312
+ return;
313
+ }
314
+
315
+ $date_v2 = "2018-07-17";
316
+ $date_new_version = new \DateTime($date_v2);
317
+ $date_j14 = new \DateTime($date_v2);
318
+ $date_j14->add(new \DateInterval('P14D'));
319
+ $date_j30 = new \DateTime($date_v2);
320
+ $date_j30->add(new \DateInterval('P1M'));
321
+ $date_j60 = new \DateTime($date_v2);
322
+ $date_j60->add(new \DateInterval('P2M'));
323
+
324
+ $date_now = new \DateTime('now');
325
+
326
+ if($date_now > $date_j60) {
327
+ return;
328
+ }
329
+
330
+ ?>
331
+ <style>
332
+ .weglot_plugin_upgrade {
333
+ font-weight: 400;
334
+ background: #fff8e5 !important;
335
+ border-left: 4px solid #ffb900;
336
+ border-top: 1px solid #ffb900;
337
+ padding: 9px 0 9px 12px !important;
338
+ margin: 0 -12px 0 -16px !important;
339
+ }
340
+
341
+ .weglot_plugin_upgrade .weglot_plugin_upgrade-sub-title {
342
+ margin-top: 10px;
343
+ font-weight: 700;
344
+ font-size: 1em;
345
+ }
346
+
347
+ .weglot_plugin_upgrade table.plugin-details-table td, .weglot_plugin_upgrade table.plugin-details-table th {
348
+ background: transparent none !important;
349
+ margin: 0;
350
+ padding: .75em 20px 0;
351
+ border: 0 !important;
352
+ font-size: 1em;
353
+ -webkit-box-shadow: none;
354
+ box-shadow: none;
355
+ }
356
+
357
+ .weglot_plugin_upgrade table.plugin-details-table tr {
358
+ background: transparent none !important;
359
+ border: 0 !important;
360
+ }
361
+
362
+ .weglot_plugin_upgrade table.plugin-details-table th {
363
+ font-weight: 700;
364
+ }
365
+
366
+ .weglot_plugin_upgrade + p {
367
+ display: none;
368
+ }
369
+
370
+ .weglot_plugin_upgrade-end {
371
+ margin-top: 10px;
372
+ }
373
+
374
+ .weglot-warning-beta {
375
+ background-color: red;
376
+ color: white;
377
+ display: inline-block;
378
+ padding: 0px 4px;
379
+ }
380
+ </style>
381
+ <div class="weglot_plugin_upgrade extensions_warning major">
382
+ <?php
383
+ if ($date_now <= $date_j14) {
384
+ $this->get_messageJ14();
385
+ } elseif ($date_now >= $date_j14 && $date_now <= $date_j30) {
386
+ $this->get_messageJ30();
387
+ } elseif ($date_now >= $date_j30 && $date_now <= $date_j60) {
388
+ $this->get_messageJ60();
389
+ }
390
+ ?>
391
+ <?php $this->weglot_updates_message_requirements(); ?>
392
+ </div>
393
+ <?php
394
  }
395
 
396
 
963
  $l,
964
  'OPTION'
965
  );
966
+ $this->modifyLink('/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/', $translatedPage, $l, 'CANONICAL');
967
+ $this->modifyLink('/<link rel="amphtml"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/', $translatedPage, $l, 'AMP');
968
  $this->modifyLink('/<meta property="og:url"(.*?)?content=(\"|\')([^\s\>]+?)(\"|\')/', $translatedPage, $l, 'META');
969
 
970
 
1103
  ) . $quote2 . '$2>', $translatedPage);
1104
  }
1105
 
1106
+ public function replaceCANONICAL(
1107
  &$translatedPage,
1108
  $current_url,
1109
  $l,
1119
  $quote2, '/') . '/', '<link rel="canonical"' . $sometags . 'href=' . $quote1 . $this->replaceUrl($current_url, $l) . $quote2, $translatedPage);
1120
  }
1121
 
1122
+ public function replaceAMP(
1123
+ &$translatedPage,
1124
+ $current_url,
1125
+ $l,
1126
+ $quote1,
1127
+ $quote2,
1128
+ $sometags = null,
1129
+ $sometags2 = null
1130
+ ) {
1131
+ $translatedPage = preg_replace('/<link rel="amphtml"' . preg_quote(
1132
+ $sometags,
1133
+ '/'
1134
+ ) . 'href=' . preg_quote($quote1 . $current_url .
1135
+ $quote2, '/') . '/', '<link rel="amphtml"' . $sometags . 'href=' . $quote1 . $this->replaceUrl($current_url, $l) . $quote2, $translatedPage);
1136
+ }
1137
+
1138
  public function replaceMETA(
1139
  &$translatedPage,
1140
  $current_url,
1282
 
1283
  public function getRequestUri($home_dir)
1284
  {
1285
+ if ($home_dir ) {
1286
+ return $this->str_replace_first($home_dir, '', $_SERVER['REQUEST_URI']);
1287
  } else {
1288
  return $_SERVER['REQUEST_URI'];
1289
  }
1290
  }
1291
+
1292
+ public function str_replace_first($from, $to, $content)
1293
+ {
1294
+ $from = '/'.preg_quote($from, '/').'/';
1295
+
1296
+ return preg_replace($from, $to, $content, 1);
1297
+ }
1298
+
1299
+
1300
  public function getLangFromUrl($request_uri)
1301
  {
1302
  $l = null;
1375
 
1376
  foreach ($destEx as $d) {
1377
  if ($d != $current) {
1378
+
1379
+ $full_url = (WeglotContext::getCurrentLanguage() != WeglotContext::getOriginalLanguage()) ? str_replace('/' . WeglotContext::getCurrentLanguage() . '/', '/', $this->full_url($_SERVER)) : $this->full_url($_SERVER);
1380
+
1381
+ $link = ($d != WeglotContext::getOriginalLanguage()) ? $this->replaceUrl($full_url, $d) : WeglotContext::getHomeDirectory().$this->request_uri_no_language;
1382
  if ($link == WeglotContext::getHomeDirectory().'/' && get_option('wg_auto_switch') == 'on') {
1383
  $link = $link . '?no_lredirect=true';
1384
  }