Changeset 3454249
- Timestamp:
- 02/05/2026 05:01:46 AM (8 weeks ago)
- Location:
- linguise
- Files:
-
- 70 added
- 32 edited
- 1 copied
-
tags/2.2.21 (copied) (copied from linguise/trunk)
-
tags/2.2.21/composer.json (modified) (1 diff)
-
tags/2.2.21/languages/linguise-ar.mo (added)
-
tags/2.2.21/languages/linguise-bg_BG.mo (added)
-
tags/2.2.21/languages/linguise-cs_CZ.mo (added)
-
tags/2.2.21/languages/linguise-da_DK.mo (added)
-
tags/2.2.21/languages/linguise-de_DE.mo (added)
-
tags/2.2.21/languages/linguise-el.mo (added)
-
tags/2.2.21/languages/linguise-es_ES.mo (modified) (previous)
-
tags/2.2.21/languages/linguise-fi.mo (added)
-
tags/2.2.21/languages/linguise-fr_FR.mo (modified) (previous)
-
tags/2.2.21/languages/linguise-he_IL.mo (added)
-
tags/2.2.21/languages/linguise-hi_IN.mo (added)
-
tags/2.2.21/languages/linguise-hr.mo (added)
-
tags/2.2.21/languages/linguise-hu_HU.mo (added)
-
tags/2.2.21/languages/linguise-id_ID.mo (added)
-
tags/2.2.21/languages/linguise-it_IT.mo (added)
-
tags/2.2.21/languages/linguise-ja.mo (added)
-
tags/2.2.21/languages/linguise-ko_KR.mo (added)
-
tags/2.2.21/languages/linguise-lt.mo (added)
-
tags/2.2.21/languages/linguise-nb_NO.mo (added)
-
tags/2.2.21/languages/linguise-nl_NL.mo (added)
-
tags/2.2.21/languages/linguise-pl_PL.mo (added)
-
tags/2.2.21/languages/linguise-pt_PT.mo (added)
-
tags/2.2.21/languages/linguise-ro_RO.mo (added)
-
tags/2.2.21/languages/linguise-ru_RU.mo (added)
-
tags/2.2.21/languages/linguise-sk_SK.mo (added)
-
tags/2.2.21/languages/linguise-sl_SI.mo (added)
-
tags/2.2.21/languages/linguise-sv_SE.mo (added)
-
tags/2.2.21/languages/linguise-th.mo (added)
-
tags/2.2.21/languages/linguise-tr_TR.mo (added)
-
tags/2.2.21/languages/linguise-uk.mo (added)
-
tags/2.2.21/languages/linguise-vi.mo (added)
-
tags/2.2.21/languages/linguise-zh_CN.mo (added)
-
tags/2.2.21/languages/linguise-zh_TW.mo (added)
-
tags/2.2.21/languages/linguise.pot (added)
-
tags/2.2.21/linguise.php (modified) (2 diffs)
-
tags/2.2.21/readme.txt (modified) (2 diffs)
-
tags/2.2.21/src/AttributeHandler.php (modified) (9 diffs)
-
tags/2.2.21/src/FragmentAutoHandler.php (added)
-
tags/2.2.21/src/FragmentBase.php (modified) (3 diffs)
-
tags/2.2.21/src/FragmentHandler.php (modified) (10 diffs)
-
tags/2.2.21/src/FragmentI18nHandler.php (added)
-
tags/2.2.21/src/FragmentOverrideHandler.php (added)
-
tags/2.2.21/src/config-iframe.php (modified) (8 diffs)
-
tags/2.2.21/src/constants.php (modified) (1 diff)
-
tags/2.2.21/src/thirdparty/ajax-search-lite.php (modified) (5 diffs)
-
tags/2.2.21/src/thirdparty/surecart.php (modified) (4 diffs)
-
tags/2.2.21/vendor/autoload.php (modified) (1 diff)
-
tags/2.2.21/vendor/composer/autoload_real.php (modified) (2 diffs)
-
tags/2.2.21/vendor/composer/autoload_static.php (modified) (2 diffs)
-
tags/2.2.21/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/composer.json (modified) (1 diff)
-
trunk/languages/linguise-ar.mo (added)
-
trunk/languages/linguise-bg_BG.mo (added)
-
trunk/languages/linguise-cs_CZ.mo (added)
-
trunk/languages/linguise-da_DK.mo (added)
-
trunk/languages/linguise-de_DE.mo (added)
-
trunk/languages/linguise-el.mo (added)
-
trunk/languages/linguise-es_ES.mo (modified) (previous)
-
trunk/languages/linguise-fi.mo (added)
-
trunk/languages/linguise-fr_FR.mo (modified) (previous)
-
trunk/languages/linguise-he_IL.mo (added)
-
trunk/languages/linguise-hi_IN.mo (added)
-
trunk/languages/linguise-hr.mo (added)
-
trunk/languages/linguise-hu_HU.mo (added)
-
trunk/languages/linguise-id_ID.mo (added)
-
trunk/languages/linguise-it_IT.mo (added)
-
trunk/languages/linguise-ja.mo (added)
-
trunk/languages/linguise-ko_KR.mo (added)
-
trunk/languages/linguise-lt.mo (added)
-
trunk/languages/linguise-nb_NO.mo (added)
-
trunk/languages/linguise-nl_NL.mo (added)
-
trunk/languages/linguise-pl_PL.mo (added)
-
trunk/languages/linguise-pt_PT.mo (added)
-
trunk/languages/linguise-ro_RO.mo (added)
-
trunk/languages/linguise-ru_RU.mo (added)
-
trunk/languages/linguise-sk_SK.mo (added)
-
trunk/languages/linguise-sl_SI.mo (added)
-
trunk/languages/linguise-sv_SE.mo (added)
-
trunk/languages/linguise-th.mo (added)
-
trunk/languages/linguise-tr_TR.mo (added)
-
trunk/languages/linguise-uk.mo (added)
-
trunk/languages/linguise-vi.mo (added)
-
trunk/languages/linguise-zh_CN.mo (added)
-
trunk/languages/linguise-zh_TW.mo (added)
-
trunk/languages/linguise.pot (added)
-
trunk/linguise.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/AttributeHandler.php (modified) (9 diffs)
-
trunk/src/FragmentAutoHandler.php (added)
-
trunk/src/FragmentBase.php (modified) (3 diffs)
-
trunk/src/FragmentHandler.php (modified) (10 diffs)
-
trunk/src/FragmentI18nHandler.php (added)
-
trunk/src/FragmentOverrideHandler.php (added)
-
trunk/src/config-iframe.php (modified) (8 diffs)
-
trunk/src/constants.php (modified) (1 diff)
-
trunk/src/thirdparty/ajax-search-lite.php (modified) (5 diffs)
-
trunk/src/thirdparty/surecart.php (modified) (4 diffs)
-
trunk/vendor/autoload.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_real.php (modified) (2 diffs)
-
trunk/vendor/composer/autoload_static.php (modified) (2 diffs)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
linguise/tags/2.2.21/composer.json
r3430418 r3454249 36 36 "phpunit/php-code-coverage": "9.2.32", 37 37 "phpunit/phpunit": "9.6.24", 38 "mockery/mockery": "1.7.x-dev" 38 "mockery/mockery": "1.7.x-dev", 39 "gettext/gettext": "5.7.3" 39 40 }, 40 41 "repositories": [ -
linguise/tags/2.2.21/linguise.php
r3442930 r3454249 5 5 * Plugin URI: https://www.linguise.com/ 6 6 * Description: Linguise translation plugin 7 * Version:2.2.2 07 * Version:2.2.21 8 8 * Text Domain: linguise 9 9 * Domain Path: /languages … … 478 478 if (strpos(file_get_contents($htaccess_file), 'BEGIN GTranslate config') !== false) { 479 479 echo '<div class="error">'; 480 /* translators: %1$s: GTranslate %2$s: GTranslate */ 480 481 echo '<p>' . sprintf(esc_html__("It looks like you have %1\$s extension that hasn't been properly uninstalled and prevents Linguise from working properly, please contact our support team or remove %2\$s code from your .htaccess file.", 'linguise'), '<strong>GTranslate</strong>', '<strong>GTranslate</strong>') . '</p>'; 481 482 echo '</div>'; -
linguise/tags/2.2.21/readme.txt
r3442930 r3454249 4 4 Requires at least: 4.0 5 5 Tested up to: 6.9 6 Stable tag: 2.2.2 06 Stable tag: 2.2.21 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later … … 108 108 109 109 == Changelog == 110 = 2.2.21 = 111 - Feature: Support more languages for admin dashboard 112 110 113 = 2.2.20 = 111 114 - Feature: Support translating WPForms redirect URL -
linguise/tags/2.2.21/src/AttributeHandler.php
r3397694 r3454249 68 68 } 69 69 70 if (function_exists('apply_filters')) { 71 $current_list = apply_filters('linguise_fragment_attributes', $current_list, $html_data); 72 } 70 $current_list = apply_filters('linguise_fragment_attributes', $current_list, $html_data); 73 71 74 72 // loop through the list and add extra field, use reference … … 171 169 $html_dom = HTMLHelper::loadHTML($html_data); 172 170 if (empty($html_dom)) { 173 return []; 171 return []; // @codeCoverageIgnore 174 172 } 175 173 … … 182 180 foreach ($elements as $element) { 183 181 if ($element->nodeType !== XML_ELEMENT_NODE) { 184 continue; 182 continue; // @codeCoverageIgnore 185 183 } 186 184 … … 282 280 foreach ($elements as $element) { 283 281 if ($element->nodeType !== XML_ELEMENT_NODE) { 284 continue; 282 continue; // @codeCoverageIgnore 285 283 } 286 284 … … 308 306 $html_dom = HTMLHelper::loadHTML($html_data); 309 307 if (empty($html_dom)) { 310 return $html_data; 308 return $html_data; // @codeCoverageIgnore 311 309 } 312 310 … … 340 338 $match_data = $attr_html->getAttribute($matched['key']); 341 339 if (empty($match_data)) { 342 continue; 340 continue; // @codeCoverageIgnore 343 341 } 344 342 … … 361 359 $first_value = isset($first_fragment['value']) ? $first_fragment['value'] : null; 362 360 if (empty($first_value)) { 363 continue; 361 continue; // @codeCoverageIgnore 364 362 } 365 363 … … 375 373 $first_fragment = isset($fragment_list['fragments'][0]) ? $fragment_list['fragments'][0] : null; 376 374 if (empty($first_fragment)) { 377 continue; 375 continue; // @codeCoverageIgnore 378 376 } 379 377 380 378 $first_value = isset($first_fragment['value']) ? $first_fragment['value'] : null; 381 379 if (empty($first_value)) { 382 continue; 380 continue; // @codeCoverageIgnore 383 381 } 384 382 … … 402 400 try { 403 401 $json_data->set('$.' . $dec_key, $fragment['value']); 404 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { 405 Debug::log('Failed to set key in attributes: ' . $dec_key . ' -> ' . $e->getMessage()); 402 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { // @codeCoverageIgnore 403 Debug::log('Failed to set key in attributes: ' . $dec_key . ' -> ' . $e->getMessage()); // @codeCoverageIgnore 406 404 } 407 405 } -
linguise/tags/2.2.21/src/FragmentBase.php
r3414869 r3454249 225 225 // Run through filters, provide our current default filters 226 226 // User can change it by adding a filter and modify the array. 227 // @codeCoverageIgnoreStart 228 if (function_exists('apply_filters')) { 229 $wp_frag_list = apply_filters('linguise_fragment_filters', $merged_defaults); 230 } else { 231 $wp_frag_list = $merged_defaults; 232 } 233 // @codeCoverageIgnoreEnd 227 $wp_frag_list = apply_filters('linguise_fragment_filters', $merged_defaults); 234 228 235 229 // cache the list … … 493 487 494 488 /** 489 * Clean up the fragments from the HTML data. 490 * 491 * @param string $html_data The HTML data to be cleaned up 492 * @param array $fragments The array of fragments to be cleaned up, from intoJSONFragments 493 * 494 * @return string 495 */ 496 protected static function cleanupFragments($html_data, $fragments) 497 { 498 foreach ($fragments as $fragment) { 499 // remove the html fragment from the translated page 500 $html_data = str_replace($fragment['match'], '', $html_data); 501 } 502 503 return $html_data; 504 } 505 506 /** 495 507 * Get override JSON fragment matching 496 508 * … … 607 619 608 620 // Merge with apply_filters 609 // @codeCoverageIgnoreStart 610 if (function_exists('apply_filters')) { 611 $current_list = apply_filters('linguise_fragment_override', $current_list, $html_data); 612 } 613 // @codeCoverageIgnoreEnd 621 $current_list = apply_filters('linguise_fragment_override', $current_list, $html_data); 614 622 615 623 return $current_list; -
linguise/tags/2.2.21/src/FragmentHandler.php
r3428799 r3454249 6 6 use Linguise\WordPress\Helper; 7 7 use Linguise\WordPress\HTMLHelper; 8 use Linguise\Vendor\JsonPath\JsonObject;9 8 use Linguise\Vendor\Linguise\Script\Core\Debug; 10 9 11 10 defined('ABSPATH') || die(''); 11 12 require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentOverrideHandler.php'; 13 require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentAutoHandler.php'; 14 require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentI18nHandler.php'; 12 15 13 16 /** … … 148 151 return $result; 149 152 } 150 return $text; 153 return $text; // @codeCoverageIgnore 151 154 } 152 155 … … 165 168 return $result; 166 169 } 167 return $text; 170 return $text; // @codeCoverageIgnore 168 171 } 169 172 … … 331 334 private static function tryMatchWithOverride($script, $html_data) 332 335 { 333 $script_content = $script->textContent; 334 $script_id = $script->getAttribute('id'); 335 336 $override_list = self::getJSONOverrideMatcher($html_data); 337 338 $multi_matched = []; 339 foreach ($override_list as $override_item) { 340 $script_content = HTMLHelper::unclobberCdataInternal($script_content); 341 if (isset($override_item['mode']) && $override_item['mode'] === 'app_json') { 342 // If mode is app_json and key is the same 343 if (isset($override_item['key']) && $override_item['key'] === $script_id) { 344 $json_data = json_decode($script_content, true); 345 $collected_temp = self::collectFragmentFromJson($json_data); 346 if (!empty($collected_temp)) { 347 return [ 348 'name' => $override_item['name'], 349 'fragments' => $collected_temp, 350 ]; 351 } 352 } 353 354 continue; 355 } 356 357 if (isset($override_item['key']) && $override_item['key'] !== $script_id) { 358 // If the key is set and it's not the same, then we skip 359 continue; 360 } 361 362 $match_res = preg_match('/' . $override_item['match'] . '/s', $script_content, $match); 363 if ($match_res === false || $match_res === 0) { 364 continue; 365 } 366 367 // since it matches, get the JSON value. 368 $match_index = 1; 369 if (isset($override_item['position'])) { 370 $match_index = $override_item['position']; 371 } 372 373 $matched = $match[$match_index]; 374 375 if (isset($override_item['encode']) && $override_item['encode']) { 376 // decode the matched string 377 $matched = urldecode($matched); 378 } 379 380 $json_data = json_decode($matched, true); 381 382 // collect the fragment 383 $is_strict = false; 384 if (isset($override_item['strict']) && $override_item['strict']) { 385 $is_strict = true; 386 } 387 388 $collected_temp = self::collectFragmentFromJson($json_data, $is_strict); 389 if (!empty($collected_temp)) { 390 $multi_matched[] = [ 391 'name' => $override_item['name'], 392 'fragments' => $collected_temp, 393 ]; 394 } 395 } 396 397 if (empty($multi_matched)) { 398 return null; 399 } 400 401 return $multi_matched; 336 return FragmentOverrideHandler::tryMatchWithOverride($script, $html_data); 402 337 } 403 338 … … 411 346 public static function tryMatchTranslationBlock($script) 412 347 { 413 $script_content = HTMLHelper::unclobberCdataInternal($script->textContent); 414 $match_res = preg_match('/\(\s*\"([\w\-_]*)\",\s*(\{.*?\})\s*\);/si', $script_content, $json_match); 415 if ($match_res === false || $match_res === 0) { 416 return null; 417 } 418 419 $block_name = $json_match[1]; 420 $json_data = json_decode($json_match[2], true); 421 if (is_null($json_data)) { 422 return null; 423 } 424 425 // WP uses Jed format for translation blocks 426 // https://messageformat.github.io/Jed/ 427 $selected_locale_data = null; 428 if (isset($json_data['locale_data'][$block_name]) && !empty($json_data['locale_data'][$block_name])) { 429 $selected_locale_data = $json_data['locale_data'][$block_name]; 430 return null; 431 } elseif (isset($json_data['locale_data']['messages']) && !empty($json_data['locale_data']['messages'])) { 432 $block_name = 'messages'; // use messages as block name 433 $selected_locale_data = $json_data['locale_data']['messages']; 434 } 435 436 if (is_null($selected_locale_data)) { 437 return null; 438 } 439 440 $collected_temp = []; 441 foreach ($selected_locale_data as $msg_key => $msg_values) { 442 if ($msg_key === '') { 443 // Skip the header 444 continue; 445 } 446 447 if (is_array($msg_values)) { 448 // for use index 449 for ($i = 0; $i < count($msg_values); $i++) { // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed 450 // hash $msg_key in sha256 to avoid issues with quotes/special chars 451 $key_hashed = hash('sha256', $msg_key); 452 $collected_temp[] = [ 453 'key' => $key_hashed, 454 'value' => $msg_values[$i], 455 'format' => 'text', 456 'index' => $i 457 ]; 458 } 459 } 460 } 461 462 return [ 463 'name' => $block_name, 464 'fragments' => $collected_temp 465 ]; 348 return FragmentI18nHandler::tryMatchTranslationBlock($script); 466 349 } 467 350 … … 478 361 $html_dom = HTMLHelper::loadHTML($html_data); 479 362 if (empty($html_dom)) { 480 return []; 363 return []; // @codeCoverageIgnore 481 364 } 482 365 … … 585 468 public static function applyTranslatedFragmentsForOverride($html_data, $fragment_name, $fragment_param, $fragment_info) 586 469 { 587 $fragment_matcher = self::getJSONOverrideMatcher($html_data); 588 589 // Find the one that match $fragment_name 590 $matched_fragment = null; 591 foreach ($fragment_matcher as $fragment_match) { 592 if ($fragment_match['name'] === $fragment_name) { 593 $matched_fragment = $fragment_match; 594 break; 595 } 596 } 597 598 if (is_null($matched_fragment)) { 599 return $html_data; 600 } 601 602 if (isset($matched_fragment['mode']) && $matched_fragment['mode'] === 'app_json') { 603 if (!isset($matched_fragment['key'])) { 604 return $html_data; 605 } 606 607 $match_res = preg_match('/<script.*? id=["\']' . $matched_fragment['key'] . '["\'].+?>{(.*)}<\/script>/s', $html_data, $html_matches); 608 609 if ($match_res === false || $match_res === 0) { 610 return $html_data; 611 } 612 613 $match_data = $html_matches[1]; 614 $json_data = new JsonObject(json_decode('{' . $match_data . '}', true)); 615 foreach ($fragment_info['fragments'] as $fragment) { 616 if (isset($fragment['skip']) && $fragment['skip']) { 617 // If skip is true, then don't replace this fragment (but remove it) 618 continue; 619 } 620 $decoded_key = self::unwrapKey($fragment['key']); 621 $merged_key = strpos($decoded_key, '[') === 0 ? '$' . $decoded_key : '$.' . $decoded_key; 622 try { 623 $json_data->set($merged_key, $fragment['value']); 624 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { 625 Debug::log('Failed to set key in override: ' . $merged_key . ' -> ' . $e->getMessage()); 626 } 627 } 628 629 $replaced_json = $json_data->getJson(); 630 631 $html_data = str_replace('{' . $match_data . '}', $replaced_json, $html_data); 632 } else { 633 $match_res = preg_match('/' . $matched_fragment['match'] . '/s', $html_data, $html_matches); 634 if ($match_res === false || $match_res === 0) { 635 return $html_data; 636 } 637 638 $index_match = 1; 639 if (isset($matched_fragment['position'])) { 640 $index_match = $matched_fragment['position']; 641 } 642 643 $before_match = $html_matches[$index_match]; 644 $should_encode = isset($matched_fragment['encode']) && $matched_fragment['encode']; 645 if ($should_encode) { 646 $before_match = urldecode($before_match); 647 } 648 649 $json_data = new JsonObject(json_decode($before_match, true)); 650 foreach ($fragment_info['fragments'] as $fragment) { 651 if (isset($fragment['skip']) && $fragment['skip']) { 652 // If skip is true, then don't replace this fragment (but remove it) 653 continue; 654 } 655 $decoded_key = self::unwrapKey($fragment['key']); 656 $merged_key = strpos($decoded_key, '[') === 0 ? '$' . $decoded_key : '$.' . $decoded_key; 657 try { 658 $json_data->set($merged_key, $fragment['value']); 659 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { 660 Debug::log('Failed to set key in override: ' . $merged_key . ' -> ' . $e->getMessage()); 661 } 662 } 663 664 $replaced_json = $json_data->getJson(); 665 666 if (function_exists('apply_filters')) { 667 $replaced_json = apply_filters('linguise_after_apply_translated_fragments_override', $replaced_json, $fragment_name); 668 } 669 670 if ($should_encode) { 671 $replaced_json = rawurlencode($replaced_json); 672 } 673 $subst_ptrn = $matched_fragment['replacement']; 674 $subst_ptrn = str_replace('$$JSON_DATA$$', $replaced_json, $subst_ptrn); 675 676 $replacement = preg_replace('/' . $matched_fragment['match'] . '/', $subst_ptrn, $html_data, 1, $count); 677 if ($count) { 678 $html_data = $replacement; 679 } 680 } 681 682 return $html_data; 470 return FragmentOverrideHandler::applyTranslatedFragmentsForOverride($html_data, $fragment_name, $fragment_param, $fragment_info); 683 471 } 684 472 … … 693 481 public static function applyTranslatedFragmentsForAuto($json_data, $fragments) 694 482 { 695 $json_path = new JsonObject($json_data); 696 // Warn if $json_data is empty 697 if (empty($json_path->getValue())) { 698 return false; 699 } 700 701 foreach ($fragments as $fragment) { 702 if (isset($fragment['skip']) && $fragment['skip']) { 703 // If skip is true, then don't replace this fragment (but remove it) 704 continue; 705 } 706 // remove the html fragment from the translated page 707 $decoded_key = self::unwrapKey($fragment['key']); 708 try { 709 $json_path->set('$.' . $decoded_key, $fragment['value']); 710 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { 711 Debug::log('Failed to set key in auto: ' . $decoded_key . ' -> ' . $e->getMessage()); 712 } 713 } 714 715 $replaced_json = $json_path->getValue(); 716 return $replaced_json; 483 return FragmentAutoHandler::applyTranslatedFragmentsForAuto($json_data, $fragments); 717 484 } 718 485 … … 729 496 public static function applyTranslatedFragmentsForI18n($html_data, $param_name, $param_key, $fragments) 730 497 { 731 $full_param_name = $param_name . '-js-translations'; 732 $overall_matchers = preg_match('/id=["\']' . preg_quote($full_param_name) . '["\'].*?>.*?\(\s*function\(\s*domain,\s*translations\s*\)\s*\{.*?\}\s*\)\s*\(\s*["\']([\w_\-]+)["\']\s*,\s*\{(.*?)\}\s*\)\s*;.*?<\/script>/si', $html_data, $html_matches); 733 if ($overall_matchers === false || $overall_matchers === 0) { 734 return $html_data; 735 } 736 737 // Get the JSON data for replacement 738 $code_contents = $html_matches[0]; 739 $match_res = preg_match('/\(\s*\"([\w\-_]+)\",\s*(\{.*?\})\s*\);/si', $code_contents, $json_match); 740 if ($match_res === false || $match_res === 0) { 741 return $html_data; 742 } 743 744 $json_data = json_decode($json_match[2], true); 745 if (is_null($json_data)) { 746 return $html_data; 747 } 748 749 $message_data = $json_data['locale_data'][$param_key]; 750 if (empty($message_data)) { 751 return $html_data; 752 } 753 754 $remapped_fragments = []; 755 foreach ($fragments as $fragment) { 756 if (isset($fragment['skip']) && $fragment['skip']) { 757 // If skip is true, then don't replace this fragment (but remove it) 758 continue; 759 } 760 761 $msg_key = $fragment['key']; 762 $msg_index = isset($fragment['index']) ? $fragment['index'] : 0; 763 764 $remapped_fragments[$msg_key] = []; 765 $remapped_fragments[$msg_key][$msg_index] = $fragment['value']; 766 } 767 768 foreach ($message_data as $msg_key => &$msg_values) { 769 if (is_array($msg_values)) { 770 $hashed_key = hash('sha256', $msg_key); 771 if (!isset($remapped_fragments[$hashed_key])) { 772 continue; 773 } 774 775 // for use index 776 for ($i = 0; $i < count($msg_values); $i++) { // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed 777 if (isset($remapped_fragments[$hashed_key][$i])) { 778 $msg_values[$i] = $remapped_fragments[$hashed_key][$i]; 779 } 780 } 781 } 782 } 783 784 $json_data['locale_data'][$param_key] = $message_data; 785 786 // dump back to JSON 787 $replaced_json = json_encode($json_data); 788 $substr_ptrn = '/(id=["\']' . preg_quote($full_param_name) . '["\'].*?>.*?\(\s*function\(\s*domain,\s*translations\s*\)\s*\{.*?\}\s*\)\s*\(\s*["\']([\w_\-]+)["\']\s*,\s*)(.*?)(\s*\)\s*;.*?<\/script>)/si'; 789 790 $replacement = preg_replace($substr_ptrn, '$1' . $replaced_json . '$4', $html_data, 1, $count); 791 if ($count) { 792 $html_data = $replacement; 793 } 794 795 return $html_data; 796 } 797 798 /** 799 * Clean up the fragments from the HTML data. 800 * 801 * @param string $html_data The HTML data to be cleaned up 802 * @param array $fragments The array of fragments to be cleaned up, from intoJSONFragments 803 * 804 * @return string 805 */ 806 protected static function cleanupFragments($html_data, $fragments) 807 { 808 foreach ($fragments as $fragment) { 809 // remove the html fragment from the translated page 810 $html_data = str_replace($fragment['match'], '', $html_data); 811 } 812 813 return $html_data; 498 return FragmentI18nHandler::applyTranslatedFragmentsForI18n($html_data, $param_name, $param_key, $fragments); 814 499 } 815 500 … … 865 550 $replaced_json = self::applyTranslatedFragmentsForAuto(json_decode('{' . $html_matches[3] . '}', true), $fragment_list['fragments']); 866 551 867 if (function_exists('apply_filters')) { 868 $replaced_json = apply_filters('linguise_after_apply_translated_fragments_auto', $replaced_json, $fragment_name); 869 } 552 $replaced_json = apply_filters('linguise_after_apply_translated_fragments_auto', $replaced_json, $fragment_name); 870 553 871 554 if ($replaced_json === false) { 872 throw new \LogicException('FragmentHandler -> Injection -> ' . $fragment_name . '/' . $fragment_param . ' -> JSON data is empty!'); 555 throw new \LogicException('FragmentHandler -> Injection -> ' . $fragment_name . '/' . $fragment_param . ' -> JSON data is empty!'); // @codeCoverageIgnore 873 556 } 874 557 -
linguise/tags/2.2.21/src/config-iframe.php
r3430418 r3454249 8 8 'message' => __('Nonce verification failed', 'linguise') 9 9 )); 10 return; 10 11 } 11 12 … … 16 17 'message' => __('User is not logged in', 'linguise') 17 18 )); 19 return; 18 20 } 19 21 // check if user has permission to manage options … … 23 25 'message' => __('User does not have permission to manage options', 'linguise') 24 26 )); 27 return; 25 28 } 26 29 … … 31 34 'message' => __('No data to update', 'linguise') 32 35 )); 36 return; 33 37 } 34 38 … … 53 57 ) 54 58 )); 59 return; 55 60 } 56 61 } … … 102 107 'back_link' => true, 103 108 )); 109 return; 104 110 } 105 111 … … 111 117 'back_link' => true, 112 118 )); 119 return; 113 120 } 114 121 // check if user has permission to manage options … … 119 126 'back_link' => true, 120 127 )); 128 return; 121 129 } 122 130 -
linguise/tags/2.2.21/src/constants.php
r3442930 r3454249 1 1 <?php 2 2 if (!defined('LINGUISE_SCRIPT_TRANSLATION_VERSION')) { 3 define('LINGUISE_SCRIPT_TRANSLATION_VERSION', 'wordpress_plugin/2.2.2 0');3 define('LINGUISE_SCRIPT_TRANSLATION_VERSION', 'wordpress_plugin/2.2.21'); 4 4 } 5 5 6 6 if (!defined('LINGUISE_VERSION')) { 7 define('LINGUISE_VERSION', '2.2.2 0');7 define('LINGUISE_VERSION', '2.2.21'); 8 8 } -
linguise/tags/2.2.21/src/thirdparty/ajax-search-lite.php
r3425738 r3454249 86 86 * Unload the integration 87 87 * 88 * @codeCoverageIgnore 89 * 88 90 * @return void 89 91 */ 90 92 public function destroy() 91 93 { 92 remove_filter('asl_query_args', [$this, 'translateSearchQuery'], 10 , 1);93 remove_filter('asl_print_search_query', [$this, 'replaceBackoriginalQuery'], 10 , 1);94 remove_filter('script_loader_tag', [$this, 'addHtmlAttribute'], 10 , 3);94 remove_filter('asl_query_args', [$this, 'translateSearchQuery'], 10); 95 remove_filter('asl_print_search_query', [$this, 'replaceBackoriginalQuery'], 10); 96 remove_filter('script_loader_tag', [$this, 'addHtmlAttribute'], 10); 95 97 96 98 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No action 97 99 if (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'ajaxsearchlite_search') { 98 add_filter('asl_before_ajax_output', [$this, 'translateAjaxResult'], 10, 1);100 remove_filter('asl_before_ajax_output', [$this, 'translateAjaxResult'], 10); 99 101 } 100 102 } … … 159 161 $query_args['s'] = $translated_query; 160 162 } 161 163 162 164 return $query_args; 163 165 } … … 195 197 public function addHtmlAttribute($tag, $handle, $src) 196 198 { 197 198 199 if (is_plugin_active('litespeed-cache/litespeed-cache.php')) { 199 200 if ($handle === 'wd-asl-ajaxsearchlite') { … … 215 216 public function translateAjaxResult($html_result) 216 217 { 217 218 218 $language = WPHelper::getLanguageFromReferer(); 219 219 … … 242 242 if (!$matches) { 243 243 // No body match 244 return $html_result; 244 return $html_result; // @codeCoverageIgnore 245 245 } 246 246 -
linguise/tags/2.2.21/src/thirdparty/surecart.php
r3339453 r3454249 354 354 $contexts[] = [ 355 355 'context' => $match[0], 356 'data' => json_decode('{' . $match[1] . '}' ),356 'data' => json_decode('{' . $match[1] . '}', true), 357 357 ]; 358 358 } … … 368 368 $context = $contexts[$index]; 369 369 if (empty($context['data'])) { 370 continue; 370 continue; // @codeCoverageIgnore 371 371 } 372 372 $fragments = FragmentHandler::collectFragmentFromJson($context['data']); … … 418 418 $index = (int)str_replace('index-', '', $key_prefix); 419 419 // Find the context 420 $context = $contexts[$index]; 421 if (empty($context)) { 420 if (!isset($contexts[$index]) || empty($contexts[$index])) { 422 421 continue; 423 422 } 423 $context = $contexts[$index]; 424 424 425 425 $tl_json_frag_list = $tl_json_frag['fragments']; 426 426 if (empty($tl_json_frag_list)) { 427 continue; 427 continue; // @codeCoverageIgnore 428 428 } 429 429 … … 462 462 return $repl_block_content; 463 463 } 464 return $block_content; 464 return $block_content; // @codeCoverageIgnore 465 465 } 466 466 -
linguise/tags/2.2.21/vendor/autoload.php
r3425738 r3454249 23 23 require_once __DIR__ . '/composer/autoload_real.php'; 24 24 25 return ComposerAutoloaderInit 7960a36ebaed5635997fc39c8c154bac::getLoader();25 return ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3::getLoader(); -
linguise/tags/2.2.21/vendor/composer/autoload_real.php
r3425738 r3454249 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit 7960a36ebaed5635997fc39c8c154bac5 class ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3 6 6 { 7 7 private static $loader; … … 23 23 } 24 24 25 spl_autoload_register(array('ComposerAutoloaderInit 7960a36ebaed5635997fc39c8c154bac', 'loadClassLoader'), true, true);25 spl_autoload_register(array('ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3', 'loadClassLoader'), true, true); 26 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 27 spl_autoload_unregister(array('ComposerAutoloaderInit 7960a36ebaed5635997fc39c8c154bac', 'loadClassLoader'));27 spl_autoload_unregister(array('ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3', 'loadClassLoader')); 28 28 29 29 require __DIR__ . '/autoload_static.php'; 30 call_user_func(\Composer\Autoload\ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::getInitializer($loader));30 call_user_func(\Composer\Autoload\ComposerStaticInitc42aec6a4150974a31712053598e6fb3::getInitializer($loader)); 31 31 32 32 $loader->register(true); 33 33 34 $filesToLoad = \Composer\Autoload\ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::$files;34 $filesToLoad = \Composer\Autoload\ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$files; 35 35 $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { 36 36 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { -
linguise/tags/2.2.21/vendor/composer/autoload_static.php
r3425738 r3454249 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac7 class ComposerStaticInitc42aec6a4150974a31712053598e6fb3 8 8 { 9 9 public static $files = array ( … … 156 156 { 157 157 return \Closure::bind(function () use ($loader) { 158 $loader->prefixLengthsPsr4 = ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::$prefixLengthsPsr4;159 $loader->prefixDirsPsr4 = ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::$prefixDirsPsr4;160 $loader->classMap = ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::$classMap;158 $loader->prefixLengthsPsr4 = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$prefixLengthsPsr4; 159 $loader->prefixDirsPsr4 = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$prefixDirsPsr4; 160 $loader->classMap = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$classMap; 161 161 162 162 }, null, ClassLoader::class); -
linguise/tags/2.2.21/vendor/composer/installed.php
r3442930 r3454249 4 4 'pretty_version' => 'dev-master', 5 5 'version' => 'dev-master', 6 'reference' => ' 354f19240a11160636da0632f88c9c6f875a58b2',6 'reference' => '4be8301399bf629dadffa1fbb936c0a2eabc3874', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 32 32 'pretty_version' => 'dev-master', 33 33 'version' => 'dev-master', 34 'reference' => ' 354f19240a11160636da0632f88c9c6f875a58b2',34 'reference' => '4be8301399bf629dadffa1fbb936c0a2eabc3874', 35 35 'type' => 'library', 36 36 'install_path' => __DIR__ . '/../../', -
linguise/trunk/composer.json
r3430418 r3454249 36 36 "phpunit/php-code-coverage": "9.2.32", 37 37 "phpunit/phpunit": "9.6.24", 38 "mockery/mockery": "1.7.x-dev" 38 "mockery/mockery": "1.7.x-dev", 39 "gettext/gettext": "5.7.3" 39 40 }, 40 41 "repositories": [ -
linguise/trunk/linguise.php
r3442930 r3454249 5 5 * Plugin URI: https://www.linguise.com/ 6 6 * Description: Linguise translation plugin 7 * Version:2.2.2 07 * Version:2.2.21 8 8 * Text Domain: linguise 9 9 * Domain Path: /languages … … 478 478 if (strpos(file_get_contents($htaccess_file), 'BEGIN GTranslate config') !== false) { 479 479 echo '<div class="error">'; 480 /* translators: %1$s: GTranslate %2$s: GTranslate */ 480 481 echo '<p>' . sprintf(esc_html__("It looks like you have %1\$s extension that hasn't been properly uninstalled and prevents Linguise from working properly, please contact our support team or remove %2\$s code from your .htaccess file.", 'linguise'), '<strong>GTranslate</strong>', '<strong>GTranslate</strong>') . '</p>'; 481 482 echo '</div>'; -
linguise/trunk/readme.txt
r3442930 r3454249 4 4 Requires at least: 4.0 5 5 Tested up to: 6.9 6 Stable tag: 2.2.2 06 Stable tag: 2.2.21 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later … … 108 108 109 109 == Changelog == 110 = 2.2.21 = 111 - Feature: Support more languages for admin dashboard 112 110 113 = 2.2.20 = 111 114 - Feature: Support translating WPForms redirect URL -
linguise/trunk/src/AttributeHandler.php
r3397694 r3454249 68 68 } 69 69 70 if (function_exists('apply_filters')) { 71 $current_list = apply_filters('linguise_fragment_attributes', $current_list, $html_data); 72 } 70 $current_list = apply_filters('linguise_fragment_attributes', $current_list, $html_data); 73 71 74 72 // loop through the list and add extra field, use reference … … 171 169 $html_dom = HTMLHelper::loadHTML($html_data); 172 170 if (empty($html_dom)) { 173 return []; 171 return []; // @codeCoverageIgnore 174 172 } 175 173 … … 182 180 foreach ($elements as $element) { 183 181 if ($element->nodeType !== XML_ELEMENT_NODE) { 184 continue; 182 continue; // @codeCoverageIgnore 185 183 } 186 184 … … 282 280 foreach ($elements as $element) { 283 281 if ($element->nodeType !== XML_ELEMENT_NODE) { 284 continue; 282 continue; // @codeCoverageIgnore 285 283 } 286 284 … … 308 306 $html_dom = HTMLHelper::loadHTML($html_data); 309 307 if (empty($html_dom)) { 310 return $html_data; 308 return $html_data; // @codeCoverageIgnore 311 309 } 312 310 … … 340 338 $match_data = $attr_html->getAttribute($matched['key']); 341 339 if (empty($match_data)) { 342 continue; 340 continue; // @codeCoverageIgnore 343 341 } 344 342 … … 361 359 $first_value = isset($first_fragment['value']) ? $first_fragment['value'] : null; 362 360 if (empty($first_value)) { 363 continue; 361 continue; // @codeCoverageIgnore 364 362 } 365 363 … … 375 373 $first_fragment = isset($fragment_list['fragments'][0]) ? $fragment_list['fragments'][0] : null; 376 374 if (empty($first_fragment)) { 377 continue; 375 continue; // @codeCoverageIgnore 378 376 } 379 377 380 378 $first_value = isset($first_fragment['value']) ? $first_fragment['value'] : null; 381 379 if (empty($first_value)) { 382 continue; 380 continue; // @codeCoverageIgnore 383 381 } 384 382 … … 402 400 try { 403 401 $json_data->set('$.' . $dec_key, $fragment['value']); 404 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { 405 Debug::log('Failed to set key in attributes: ' . $dec_key . ' -> ' . $e->getMessage()); 402 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { // @codeCoverageIgnore 403 Debug::log('Failed to set key in attributes: ' . $dec_key . ' -> ' . $e->getMessage()); // @codeCoverageIgnore 406 404 } 407 405 } -
linguise/trunk/src/FragmentBase.php
r3414869 r3454249 225 225 // Run through filters, provide our current default filters 226 226 // User can change it by adding a filter and modify the array. 227 // @codeCoverageIgnoreStart 228 if (function_exists('apply_filters')) { 229 $wp_frag_list = apply_filters('linguise_fragment_filters', $merged_defaults); 230 } else { 231 $wp_frag_list = $merged_defaults; 232 } 233 // @codeCoverageIgnoreEnd 227 $wp_frag_list = apply_filters('linguise_fragment_filters', $merged_defaults); 234 228 235 229 // cache the list … … 493 487 494 488 /** 489 * Clean up the fragments from the HTML data. 490 * 491 * @param string $html_data The HTML data to be cleaned up 492 * @param array $fragments The array of fragments to be cleaned up, from intoJSONFragments 493 * 494 * @return string 495 */ 496 protected static function cleanupFragments($html_data, $fragments) 497 { 498 foreach ($fragments as $fragment) { 499 // remove the html fragment from the translated page 500 $html_data = str_replace($fragment['match'], '', $html_data); 501 } 502 503 return $html_data; 504 } 505 506 /** 495 507 * Get override JSON fragment matching 496 508 * … … 607 619 608 620 // Merge with apply_filters 609 // @codeCoverageIgnoreStart 610 if (function_exists('apply_filters')) { 611 $current_list = apply_filters('linguise_fragment_override', $current_list, $html_data); 612 } 613 // @codeCoverageIgnoreEnd 621 $current_list = apply_filters('linguise_fragment_override', $current_list, $html_data); 614 622 615 623 return $current_list; -
linguise/trunk/src/FragmentHandler.php
r3428799 r3454249 6 6 use Linguise\WordPress\Helper; 7 7 use Linguise\WordPress\HTMLHelper; 8 use Linguise\Vendor\JsonPath\JsonObject;9 8 use Linguise\Vendor\Linguise\Script\Core\Debug; 10 9 11 10 defined('ABSPATH') || die(''); 11 12 require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentOverrideHandler.php'; 13 require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentAutoHandler.php'; 14 require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentI18nHandler.php'; 12 15 13 16 /** … … 148 151 return $result; 149 152 } 150 return $text; 153 return $text; // @codeCoverageIgnore 151 154 } 152 155 … … 165 168 return $result; 166 169 } 167 return $text; 170 return $text; // @codeCoverageIgnore 168 171 } 169 172 … … 331 334 private static function tryMatchWithOverride($script, $html_data) 332 335 { 333 $script_content = $script->textContent; 334 $script_id = $script->getAttribute('id'); 335 336 $override_list = self::getJSONOverrideMatcher($html_data); 337 338 $multi_matched = []; 339 foreach ($override_list as $override_item) { 340 $script_content = HTMLHelper::unclobberCdataInternal($script_content); 341 if (isset($override_item['mode']) && $override_item['mode'] === 'app_json') { 342 // If mode is app_json and key is the same 343 if (isset($override_item['key']) && $override_item['key'] === $script_id) { 344 $json_data = json_decode($script_content, true); 345 $collected_temp = self::collectFragmentFromJson($json_data); 346 if (!empty($collected_temp)) { 347 return [ 348 'name' => $override_item['name'], 349 'fragments' => $collected_temp, 350 ]; 351 } 352 } 353 354 continue; 355 } 356 357 if (isset($override_item['key']) && $override_item['key'] !== $script_id) { 358 // If the key is set and it's not the same, then we skip 359 continue; 360 } 361 362 $match_res = preg_match('/' . $override_item['match'] . '/s', $script_content, $match); 363 if ($match_res === false || $match_res === 0) { 364 continue; 365 } 366 367 // since it matches, get the JSON value. 368 $match_index = 1; 369 if (isset($override_item['position'])) { 370 $match_index = $override_item['position']; 371 } 372 373 $matched = $match[$match_index]; 374 375 if (isset($override_item['encode']) && $override_item['encode']) { 376 // decode the matched string 377 $matched = urldecode($matched); 378 } 379 380 $json_data = json_decode($matched, true); 381 382 // collect the fragment 383 $is_strict = false; 384 if (isset($override_item['strict']) && $override_item['strict']) { 385 $is_strict = true; 386 } 387 388 $collected_temp = self::collectFragmentFromJson($json_data, $is_strict); 389 if (!empty($collected_temp)) { 390 $multi_matched[] = [ 391 'name' => $override_item['name'], 392 'fragments' => $collected_temp, 393 ]; 394 } 395 } 396 397 if (empty($multi_matched)) { 398 return null; 399 } 400 401 return $multi_matched; 336 return FragmentOverrideHandler::tryMatchWithOverride($script, $html_data); 402 337 } 403 338 … … 411 346 public static function tryMatchTranslationBlock($script) 412 347 { 413 $script_content = HTMLHelper::unclobberCdataInternal($script->textContent); 414 $match_res = preg_match('/\(\s*\"([\w\-_]*)\",\s*(\{.*?\})\s*\);/si', $script_content, $json_match); 415 if ($match_res === false || $match_res === 0) { 416 return null; 417 } 418 419 $block_name = $json_match[1]; 420 $json_data = json_decode($json_match[2], true); 421 if (is_null($json_data)) { 422 return null; 423 } 424 425 // WP uses Jed format for translation blocks 426 // https://messageformat.github.io/Jed/ 427 $selected_locale_data = null; 428 if (isset($json_data['locale_data'][$block_name]) && !empty($json_data['locale_data'][$block_name])) { 429 $selected_locale_data = $json_data['locale_data'][$block_name]; 430 return null; 431 } elseif (isset($json_data['locale_data']['messages']) && !empty($json_data['locale_data']['messages'])) { 432 $block_name = 'messages'; // use messages as block name 433 $selected_locale_data = $json_data['locale_data']['messages']; 434 } 435 436 if (is_null($selected_locale_data)) { 437 return null; 438 } 439 440 $collected_temp = []; 441 foreach ($selected_locale_data as $msg_key => $msg_values) { 442 if ($msg_key === '') { 443 // Skip the header 444 continue; 445 } 446 447 if (is_array($msg_values)) { 448 // for use index 449 for ($i = 0; $i < count($msg_values); $i++) { // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed 450 // hash $msg_key in sha256 to avoid issues with quotes/special chars 451 $key_hashed = hash('sha256', $msg_key); 452 $collected_temp[] = [ 453 'key' => $key_hashed, 454 'value' => $msg_values[$i], 455 'format' => 'text', 456 'index' => $i 457 ]; 458 } 459 } 460 } 461 462 return [ 463 'name' => $block_name, 464 'fragments' => $collected_temp 465 ]; 348 return FragmentI18nHandler::tryMatchTranslationBlock($script); 466 349 } 467 350 … … 478 361 $html_dom = HTMLHelper::loadHTML($html_data); 479 362 if (empty($html_dom)) { 480 return []; 363 return []; // @codeCoverageIgnore 481 364 } 482 365 … … 585 468 public static function applyTranslatedFragmentsForOverride($html_data, $fragment_name, $fragment_param, $fragment_info) 586 469 { 587 $fragment_matcher = self::getJSONOverrideMatcher($html_data); 588 589 // Find the one that match $fragment_name 590 $matched_fragment = null; 591 foreach ($fragment_matcher as $fragment_match) { 592 if ($fragment_match['name'] === $fragment_name) { 593 $matched_fragment = $fragment_match; 594 break; 595 } 596 } 597 598 if (is_null($matched_fragment)) { 599 return $html_data; 600 } 601 602 if (isset($matched_fragment['mode']) && $matched_fragment['mode'] === 'app_json') { 603 if (!isset($matched_fragment['key'])) { 604 return $html_data; 605 } 606 607 $match_res = preg_match('/<script.*? id=["\']' . $matched_fragment['key'] . '["\'].+?>{(.*)}<\/script>/s', $html_data, $html_matches); 608 609 if ($match_res === false || $match_res === 0) { 610 return $html_data; 611 } 612 613 $match_data = $html_matches[1]; 614 $json_data = new JsonObject(json_decode('{' . $match_data . '}', true)); 615 foreach ($fragment_info['fragments'] as $fragment) { 616 if (isset($fragment['skip']) && $fragment['skip']) { 617 // If skip is true, then don't replace this fragment (but remove it) 618 continue; 619 } 620 $decoded_key = self::unwrapKey($fragment['key']); 621 $merged_key = strpos($decoded_key, '[') === 0 ? '$' . $decoded_key : '$.' . $decoded_key; 622 try { 623 $json_data->set($merged_key, $fragment['value']); 624 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { 625 Debug::log('Failed to set key in override: ' . $merged_key . ' -> ' . $e->getMessage()); 626 } 627 } 628 629 $replaced_json = $json_data->getJson(); 630 631 $html_data = str_replace('{' . $match_data . '}', $replaced_json, $html_data); 632 } else { 633 $match_res = preg_match('/' . $matched_fragment['match'] . '/s', $html_data, $html_matches); 634 if ($match_res === false || $match_res === 0) { 635 return $html_data; 636 } 637 638 $index_match = 1; 639 if (isset($matched_fragment['position'])) { 640 $index_match = $matched_fragment['position']; 641 } 642 643 $before_match = $html_matches[$index_match]; 644 $should_encode = isset($matched_fragment['encode']) && $matched_fragment['encode']; 645 if ($should_encode) { 646 $before_match = urldecode($before_match); 647 } 648 649 $json_data = new JsonObject(json_decode($before_match, true)); 650 foreach ($fragment_info['fragments'] as $fragment) { 651 if (isset($fragment['skip']) && $fragment['skip']) { 652 // If skip is true, then don't replace this fragment (but remove it) 653 continue; 654 } 655 $decoded_key = self::unwrapKey($fragment['key']); 656 $merged_key = strpos($decoded_key, '[') === 0 ? '$' . $decoded_key : '$.' . $decoded_key; 657 try { 658 $json_data->set($merged_key, $fragment['value']); 659 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { 660 Debug::log('Failed to set key in override: ' . $merged_key . ' -> ' . $e->getMessage()); 661 } 662 } 663 664 $replaced_json = $json_data->getJson(); 665 666 if (function_exists('apply_filters')) { 667 $replaced_json = apply_filters('linguise_after_apply_translated_fragments_override', $replaced_json, $fragment_name); 668 } 669 670 if ($should_encode) { 671 $replaced_json = rawurlencode($replaced_json); 672 } 673 $subst_ptrn = $matched_fragment['replacement']; 674 $subst_ptrn = str_replace('$$JSON_DATA$$', $replaced_json, $subst_ptrn); 675 676 $replacement = preg_replace('/' . $matched_fragment['match'] . '/', $subst_ptrn, $html_data, 1, $count); 677 if ($count) { 678 $html_data = $replacement; 679 } 680 } 681 682 return $html_data; 470 return FragmentOverrideHandler::applyTranslatedFragmentsForOverride($html_data, $fragment_name, $fragment_param, $fragment_info); 683 471 } 684 472 … … 693 481 public static function applyTranslatedFragmentsForAuto($json_data, $fragments) 694 482 { 695 $json_path = new JsonObject($json_data); 696 // Warn if $json_data is empty 697 if (empty($json_path->getValue())) { 698 return false; 699 } 700 701 foreach ($fragments as $fragment) { 702 if (isset($fragment['skip']) && $fragment['skip']) { 703 // If skip is true, then don't replace this fragment (but remove it) 704 continue; 705 } 706 // remove the html fragment from the translated page 707 $decoded_key = self::unwrapKey($fragment['key']); 708 try { 709 $json_path->set('$.' . $decoded_key, $fragment['value']); 710 } catch (\Linguise\Vendor\JsonPath\InvalidJsonPathException $e) { 711 Debug::log('Failed to set key in auto: ' . $decoded_key . ' -> ' . $e->getMessage()); 712 } 713 } 714 715 $replaced_json = $json_path->getValue(); 716 return $replaced_json; 483 return FragmentAutoHandler::applyTranslatedFragmentsForAuto($json_data, $fragments); 717 484 } 718 485 … … 729 496 public static function applyTranslatedFragmentsForI18n($html_data, $param_name, $param_key, $fragments) 730 497 { 731 $full_param_name = $param_name . '-js-translations'; 732 $overall_matchers = preg_match('/id=["\']' . preg_quote($full_param_name) . '["\'].*?>.*?\(\s*function\(\s*domain,\s*translations\s*\)\s*\{.*?\}\s*\)\s*\(\s*["\']([\w_\-]+)["\']\s*,\s*\{(.*?)\}\s*\)\s*;.*?<\/script>/si', $html_data, $html_matches); 733 if ($overall_matchers === false || $overall_matchers === 0) { 734 return $html_data; 735 } 736 737 // Get the JSON data for replacement 738 $code_contents = $html_matches[0]; 739 $match_res = preg_match('/\(\s*\"([\w\-_]+)\",\s*(\{.*?\})\s*\);/si', $code_contents, $json_match); 740 if ($match_res === false || $match_res === 0) { 741 return $html_data; 742 } 743 744 $json_data = json_decode($json_match[2], true); 745 if (is_null($json_data)) { 746 return $html_data; 747 } 748 749 $message_data = $json_data['locale_data'][$param_key]; 750 if (empty($message_data)) { 751 return $html_data; 752 } 753 754 $remapped_fragments = []; 755 foreach ($fragments as $fragment) { 756 if (isset($fragment['skip']) && $fragment['skip']) { 757 // If skip is true, then don't replace this fragment (but remove it) 758 continue; 759 } 760 761 $msg_key = $fragment['key']; 762 $msg_index = isset($fragment['index']) ? $fragment['index'] : 0; 763 764 $remapped_fragments[$msg_key] = []; 765 $remapped_fragments[$msg_key][$msg_index] = $fragment['value']; 766 } 767 768 foreach ($message_data as $msg_key => &$msg_values) { 769 if (is_array($msg_values)) { 770 $hashed_key = hash('sha256', $msg_key); 771 if (!isset($remapped_fragments[$hashed_key])) { 772 continue; 773 } 774 775 // for use index 776 for ($i = 0; $i < count($msg_values); $i++) { // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed 777 if (isset($remapped_fragments[$hashed_key][$i])) { 778 $msg_values[$i] = $remapped_fragments[$hashed_key][$i]; 779 } 780 } 781 } 782 } 783 784 $json_data['locale_data'][$param_key] = $message_data; 785 786 // dump back to JSON 787 $replaced_json = json_encode($json_data); 788 $substr_ptrn = '/(id=["\']' . preg_quote($full_param_name) . '["\'].*?>.*?\(\s*function\(\s*domain,\s*translations\s*\)\s*\{.*?\}\s*\)\s*\(\s*["\']([\w_\-]+)["\']\s*,\s*)(.*?)(\s*\)\s*;.*?<\/script>)/si'; 789 790 $replacement = preg_replace($substr_ptrn, '$1' . $replaced_json . '$4', $html_data, 1, $count); 791 if ($count) { 792 $html_data = $replacement; 793 } 794 795 return $html_data; 796 } 797 798 /** 799 * Clean up the fragments from the HTML data. 800 * 801 * @param string $html_data The HTML data to be cleaned up 802 * @param array $fragments The array of fragments to be cleaned up, from intoJSONFragments 803 * 804 * @return string 805 */ 806 protected static function cleanupFragments($html_data, $fragments) 807 { 808 foreach ($fragments as $fragment) { 809 // remove the html fragment from the translated page 810 $html_data = str_replace($fragment['match'], '', $html_data); 811 } 812 813 return $html_data; 498 return FragmentI18nHandler::applyTranslatedFragmentsForI18n($html_data, $param_name, $param_key, $fragments); 814 499 } 815 500 … … 865 550 $replaced_json = self::applyTranslatedFragmentsForAuto(json_decode('{' . $html_matches[3] . '}', true), $fragment_list['fragments']); 866 551 867 if (function_exists('apply_filters')) { 868 $replaced_json = apply_filters('linguise_after_apply_translated_fragments_auto', $replaced_json, $fragment_name); 869 } 552 $replaced_json = apply_filters('linguise_after_apply_translated_fragments_auto', $replaced_json, $fragment_name); 870 553 871 554 if ($replaced_json === false) { 872 throw new \LogicException('FragmentHandler -> Injection -> ' . $fragment_name . '/' . $fragment_param . ' -> JSON data is empty!'); 555 throw new \LogicException('FragmentHandler -> Injection -> ' . $fragment_name . '/' . $fragment_param . ' -> JSON data is empty!'); // @codeCoverageIgnore 873 556 } 874 557 -
linguise/trunk/src/config-iframe.php
r3430418 r3454249 8 8 'message' => __('Nonce verification failed', 'linguise') 9 9 )); 10 return; 10 11 } 11 12 … … 16 17 'message' => __('User is not logged in', 'linguise') 17 18 )); 19 return; 18 20 } 19 21 // check if user has permission to manage options … … 23 25 'message' => __('User does not have permission to manage options', 'linguise') 24 26 )); 27 return; 25 28 } 26 29 … … 31 34 'message' => __('No data to update', 'linguise') 32 35 )); 36 return; 33 37 } 34 38 … … 53 57 ) 54 58 )); 59 return; 55 60 } 56 61 } … … 102 107 'back_link' => true, 103 108 )); 109 return; 104 110 } 105 111 … … 111 117 'back_link' => true, 112 118 )); 119 return; 113 120 } 114 121 // check if user has permission to manage options … … 119 126 'back_link' => true, 120 127 )); 128 return; 121 129 } 122 130 -
linguise/trunk/src/constants.php
r3442930 r3454249 1 1 <?php 2 2 if (!defined('LINGUISE_SCRIPT_TRANSLATION_VERSION')) { 3 define('LINGUISE_SCRIPT_TRANSLATION_VERSION', 'wordpress_plugin/2.2.2 0');3 define('LINGUISE_SCRIPT_TRANSLATION_VERSION', 'wordpress_plugin/2.2.21'); 4 4 } 5 5 6 6 if (!defined('LINGUISE_VERSION')) { 7 define('LINGUISE_VERSION', '2.2.2 0');7 define('LINGUISE_VERSION', '2.2.21'); 8 8 } -
linguise/trunk/src/thirdparty/ajax-search-lite.php
r3425738 r3454249 86 86 * Unload the integration 87 87 * 88 * @codeCoverageIgnore 89 * 88 90 * @return void 89 91 */ 90 92 public function destroy() 91 93 { 92 remove_filter('asl_query_args', [$this, 'translateSearchQuery'], 10 , 1);93 remove_filter('asl_print_search_query', [$this, 'replaceBackoriginalQuery'], 10 , 1);94 remove_filter('script_loader_tag', [$this, 'addHtmlAttribute'], 10 , 3);94 remove_filter('asl_query_args', [$this, 'translateSearchQuery'], 10); 95 remove_filter('asl_print_search_query', [$this, 'replaceBackoriginalQuery'], 10); 96 remove_filter('script_loader_tag', [$this, 'addHtmlAttribute'], 10); 95 97 96 98 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No action 97 99 if (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'ajaxsearchlite_search') { 98 add_filter('asl_before_ajax_output', [$this, 'translateAjaxResult'], 10, 1);100 remove_filter('asl_before_ajax_output', [$this, 'translateAjaxResult'], 10); 99 101 } 100 102 } … … 159 161 $query_args['s'] = $translated_query; 160 162 } 161 163 162 164 return $query_args; 163 165 } … … 195 197 public function addHtmlAttribute($tag, $handle, $src) 196 198 { 197 198 199 if (is_plugin_active('litespeed-cache/litespeed-cache.php')) { 199 200 if ($handle === 'wd-asl-ajaxsearchlite') { … … 215 216 public function translateAjaxResult($html_result) 216 217 { 217 218 218 $language = WPHelper::getLanguageFromReferer(); 219 219 … … 242 242 if (!$matches) { 243 243 // No body match 244 return $html_result; 244 return $html_result; // @codeCoverageIgnore 245 245 } 246 246 -
linguise/trunk/src/thirdparty/surecart.php
r3339453 r3454249 354 354 $contexts[] = [ 355 355 'context' => $match[0], 356 'data' => json_decode('{' . $match[1] . '}' ),356 'data' => json_decode('{' . $match[1] . '}', true), 357 357 ]; 358 358 } … … 368 368 $context = $contexts[$index]; 369 369 if (empty($context['data'])) { 370 continue; 370 continue; // @codeCoverageIgnore 371 371 } 372 372 $fragments = FragmentHandler::collectFragmentFromJson($context['data']); … … 418 418 $index = (int)str_replace('index-', '', $key_prefix); 419 419 // Find the context 420 $context = $contexts[$index]; 421 if (empty($context)) { 420 if (!isset($contexts[$index]) || empty($contexts[$index])) { 422 421 continue; 423 422 } 423 $context = $contexts[$index]; 424 424 425 425 $tl_json_frag_list = $tl_json_frag['fragments']; 426 426 if (empty($tl_json_frag_list)) { 427 continue; 427 continue; // @codeCoverageIgnore 428 428 } 429 429 … … 462 462 return $repl_block_content; 463 463 } 464 return $block_content; 464 return $block_content; // @codeCoverageIgnore 465 465 } 466 466 -
linguise/trunk/vendor/autoload.php
r3425738 r3454249 23 23 require_once __DIR__ . '/composer/autoload_real.php'; 24 24 25 return ComposerAutoloaderInit 7960a36ebaed5635997fc39c8c154bac::getLoader();25 return ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3::getLoader(); -
linguise/trunk/vendor/composer/autoload_real.php
r3425738 r3454249 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit 7960a36ebaed5635997fc39c8c154bac5 class ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3 6 6 { 7 7 private static $loader; … … 23 23 } 24 24 25 spl_autoload_register(array('ComposerAutoloaderInit 7960a36ebaed5635997fc39c8c154bac', 'loadClassLoader'), true, true);25 spl_autoload_register(array('ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3', 'loadClassLoader'), true, true); 26 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 27 spl_autoload_unregister(array('ComposerAutoloaderInit 7960a36ebaed5635997fc39c8c154bac', 'loadClassLoader'));27 spl_autoload_unregister(array('ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3', 'loadClassLoader')); 28 28 29 29 require __DIR__ . '/autoload_static.php'; 30 call_user_func(\Composer\Autoload\ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::getInitializer($loader));30 call_user_func(\Composer\Autoload\ComposerStaticInitc42aec6a4150974a31712053598e6fb3::getInitializer($loader)); 31 31 32 32 $loader->register(true); 33 33 34 $filesToLoad = \Composer\Autoload\ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::$files;34 $filesToLoad = \Composer\Autoload\ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$files; 35 35 $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { 36 36 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { -
linguise/trunk/vendor/composer/autoload_static.php
r3425738 r3454249 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac7 class ComposerStaticInitc42aec6a4150974a31712053598e6fb3 8 8 { 9 9 public static $files = array ( … … 156 156 { 157 157 return \Closure::bind(function () use ($loader) { 158 $loader->prefixLengthsPsr4 = ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::$prefixLengthsPsr4;159 $loader->prefixDirsPsr4 = ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::$prefixDirsPsr4;160 $loader->classMap = ComposerStaticInit 7960a36ebaed5635997fc39c8c154bac::$classMap;158 $loader->prefixLengthsPsr4 = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$prefixLengthsPsr4; 159 $loader->prefixDirsPsr4 = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$prefixDirsPsr4; 160 $loader->classMap = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$classMap; 161 161 162 162 }, null, ClassLoader::class); -
linguise/trunk/vendor/composer/installed.php
r3442930 r3454249 4 4 'pretty_version' => 'dev-master', 5 5 'version' => 'dev-master', 6 'reference' => ' 354f19240a11160636da0632f88c9c6f875a58b2',6 'reference' => '4be8301399bf629dadffa1fbb936c0a2eabc3874', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 32 32 'pretty_version' => 'dev-master', 33 33 'version' => 'dev-master', 34 'reference' => ' 354f19240a11160636da0632f88c9c6f875a58b2',34 'reference' => '4be8301399bf629dadffa1fbb936c0a2eabc3874', 35 35 'type' => 'library', 36 36 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.