Plugin Directory

Changeset 3454249


Ignore:
Timestamp:
02/05/2026 05:01:46 AM (8 weeks ago)
Author:
linguise
Message:

Updating to version 2.2.21

Location:
linguise
Files:
70 added
32 edited
1 copied

Legend:

Unmodified
Added
Removed
  • linguise/tags/2.2.21/composer.json

    r3430418 r3454249  
    3636    "phpunit/php-code-coverage": "9.2.32",
    3737    "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"
    3940  },
    4041  "repositories": [
  • linguise/tags/2.2.21/linguise.php

    r3442930 r3454249  
    55 * Plugin URI: https://www.linguise.com/
    66 * Description: Linguise translation plugin
    7  * Version:2.2.20
     7 * Version:2.2.21
    88 * Text Domain: linguise
    99 * Domain Path: /languages
     
    478478        if (strpos(file_get_contents($htaccess_file), 'BEGIN GTranslate config') !== false) {
    479479            echo '<div class="error">';
     480            /* translators: %1$s: GTranslate %2$s: GTranslate */
    480481            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>';
    481482            echo '</div>';
  • linguise/tags/2.2.21/readme.txt

    r3442930 r3454249  
    44Requires at least: 4.0
    55Tested up to: 6.9
    6 Stable tag: 2.2.20
     6Stable tag: 2.2.21
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    108108
    109109== Changelog ==
     110= 2.2.21 =
     111- Feature: Support more languages for admin dashboard
     112
    110113= 2.2.20 =
    111114- Feature: Support translating WPForms redirect URL
  • linguise/tags/2.2.21/src/AttributeHandler.php

    r3397694 r3454249  
    6868        }
    6969
    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);
    7371
    7472        // loop through the list and add extra field, use reference
     
    171169        $html_dom = HTMLHelper::loadHTML($html_data);
    172170        if (empty($html_dom)) {
    173             return [];
     171            return []; // @codeCoverageIgnore
    174172        }
    175173
     
    182180        foreach ($elements as $element) {
    183181            if ($element->nodeType !== XML_ELEMENT_NODE) {
    184                 continue;
     182                continue; // @codeCoverageIgnore
    185183            }
    186184
     
    282280        foreach ($elements as $element) {
    283281            if ($element->nodeType !== XML_ELEMENT_NODE) {
    284                 continue;
     282                continue; // @codeCoverageIgnore
    285283            }
    286284
     
    308306        $html_dom = HTMLHelper::loadHTML($html_data);
    309307        if (empty($html_dom)) {
    310             return $html_data;
     308            return $html_data; // @codeCoverageIgnore
    311309        }
    312310
     
    340338                $match_data = $attr_html->getAttribute($matched['key']);
    341339                if (empty($match_data)) {
    342                     continue;
     340                    continue; // @codeCoverageIgnore
    343341                }
    344342
     
    361359                    $first_value = isset($first_fragment['value']) ? $first_fragment['value'] : null;
    362360                    if (empty($first_value)) {
    363                         continue;
     361                        continue; // @codeCoverageIgnore
    364362                    }
    365363
     
    375373                    $first_fragment = isset($fragment_list['fragments'][0]) ? $fragment_list['fragments'][0] : null;
    376374                    if (empty($first_fragment)) {
    377                         continue;
     375                        continue; // @codeCoverageIgnore
    378376                    }
    379377
    380378                    $first_value = isset($first_fragment['value']) ? $first_fragment['value'] : null;
    381379                    if (empty($first_value)) {
    382                         continue;
     380                        continue; // @codeCoverageIgnore
    383381                    }
    384382
     
    402400                        try {
    403401                            $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
    406404                        }
    407405                    }
  • linguise/tags/2.2.21/src/FragmentBase.php

    r3414869 r3454249  
    225225        // Run through filters, provide our current default filters
    226226        // 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);
    234228
    235229        // cache the list
     
    493487
    494488    /**
     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    /**
    495507     * Get override JSON fragment matching
    496508     *
     
    607619
    608620        // 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);
    614622
    615623        return $current_list;
  • linguise/tags/2.2.21/src/FragmentHandler.php

    r3428799 r3454249  
    66use Linguise\WordPress\Helper;
    77use Linguise\WordPress\HTMLHelper;
    8 use Linguise\Vendor\JsonPath\JsonObject;
    98use Linguise\Vendor\Linguise\Script\Core\Debug;
    109
    1110defined('ABSPATH') || die('');
     11
     12require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentOverrideHandler.php';
     13require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentAutoHandler.php';
     14require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentI18nHandler.php';
    1215
    1316/**
     
    148151            return $result;
    149152        }
    150         return $text;
     153        return $text; // @codeCoverageIgnore
    151154    }
    152155
     
    165168            return $result;
    166169        }
    167         return $text;
     170        return $text; // @codeCoverageIgnore
    168171    }
    169172
     
    331334    private static function tryMatchWithOverride($script, $html_data)
    332335    {
    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);
    402337    }
    403338
     
    411346    public static function tryMatchTranslationBlock($script)
    412347    {
    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);
    466349    }
    467350
     
    478361        $html_dom = HTMLHelper::loadHTML($html_data);
    479362        if (empty($html_dom)) {
    480             return [];
     363            return []; // @codeCoverageIgnore
    481364        }
    482365
     
    585468    public static function applyTranslatedFragmentsForOverride($html_data, $fragment_name, $fragment_param, $fragment_info)
    586469    {
    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);
    683471    }
    684472
     
    693481    public static function applyTranslatedFragmentsForAuto($json_data, $fragments)
    694482    {
    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);
    717484    }
    718485
     
    729496    public static function applyTranslatedFragmentsForI18n($html_data, $param_name, $param_key, $fragments)
    730497    {
    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);
    814499    }
    815500
     
    865550                $replaced_json = self::applyTranslatedFragmentsForAuto(json_decode('{' . $html_matches[3] . '}', true), $fragment_list['fragments']);
    866551
    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);
    870553
    871554                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
    873556                }
    874557
  • linguise/tags/2.2.21/src/config-iframe.php

    r3430418 r3454249  
    88            'message' => __('Nonce verification failed', 'linguise')
    99        ));
     10        return;
    1011    }
    1112
     
    1617            'message' => __('User is not logged in', 'linguise')
    1718        ));
     19        return;
    1820    }
    1921    // check if user has permission to manage options
     
    2325            'message' => __('User does not have permission to manage options', 'linguise')
    2426        ));
     27        return;
    2528    }
    2629
     
    3134            'message' => __('No data to update', 'linguise')
    3235        ));
     36        return;
    3337    }
    3438
     
    5357                )
    5458            ));
     59            return;
    5560        }
    5661    }
     
    102107            'back_link' => true,
    103108        ));
     109        return;
    104110    }
    105111
     
    111117            'back_link' => true,
    112118        ));
     119        return;
    113120    }
    114121    // check if user has permission to manage options
     
    119126            'back_link' => true,
    120127        ));
     128        return;
    121129    }
    122130
  • linguise/tags/2.2.21/src/constants.php

    r3442930 r3454249  
    11<?php
    22if (!defined('LINGUISE_SCRIPT_TRANSLATION_VERSION')) {
    3     define('LINGUISE_SCRIPT_TRANSLATION_VERSION', 'wordpress_plugin/2.2.20');
     3    define('LINGUISE_SCRIPT_TRANSLATION_VERSION', 'wordpress_plugin/2.2.21');
    44}
    55
    66if (!defined('LINGUISE_VERSION')) {
    7     define('LINGUISE_VERSION', '2.2.20');
     7    define('LINGUISE_VERSION', '2.2.21');
    88}
  • linguise/tags/2.2.21/src/thirdparty/ajax-search-lite.php

    r3425738 r3454249  
    8686     * Unload the integration
    8787     *
     88     * @codeCoverageIgnore
     89     *
    8890     * @return void
    8991     */
    9092    public function destroy()
    9193    {
    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);
    9597
    9698        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No action
    9799        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);
    99101        }
    100102    }
     
    159161            $query_args['s'] = $translated_query;
    160162        }
    161        
     163
    162164        return $query_args;
    163165    }
     
    195197    public function addHtmlAttribute($tag, $handle, $src)
    196198    {
    197 
    198199        if (is_plugin_active('litespeed-cache/litespeed-cache.php')) {
    199200            if ($handle === 'wd-asl-ajaxsearchlite') {
     
    215216    public function translateAjaxResult($html_result)
    216217    {
    217 
    218218        $language = WPHelper::getLanguageFromReferer();
    219219
     
    242242        if (!$matches) {
    243243            // No body match
    244             return $html_result;
     244            return $html_result; // @codeCoverageIgnore
    245245        }
    246246
  • linguise/tags/2.2.21/src/thirdparty/surecart.php

    r3339453 r3454249  
    354354            $contexts[] = [
    355355                'context' => $match[0],
    356                 'data' => json_decode('{' . $match[1] . '}'),
     356                'data' => json_decode('{' . $match[1] . '}', true),
    357357            ];
    358358        }
     
    368368            $context = $contexts[$index];
    369369            if (empty($context['data'])) {
    370                 continue;
     370                continue; // @codeCoverageIgnore
    371371            }
    372372            $fragments = FragmentHandler::collectFragmentFromJson($context['data']);
     
    418418            $index = (int)str_replace('index-', '', $key_prefix);
    419419            // Find the context
    420             $context = $contexts[$index];
    421             if (empty($context)) {
     420            if (!isset($contexts[$index]) || empty($contexts[$index])) {
    422421                continue;
    423422            }
     423            $context = $contexts[$index];
    424424
    425425            $tl_json_frag_list = $tl_json_frag['fragments'];
    426426            if (empty($tl_json_frag_list)) {
    427                 continue;
     427                continue; // @codeCoverageIgnore
    428428            }
    429429
     
    462462            return $repl_block_content;
    463463        }
    464         return $block_content;
     464        return $block_content; // @codeCoverageIgnore
    465465    }
    466466
  • linguise/tags/2.2.21/vendor/autoload.php

    r3425738 r3454249  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInit7960a36ebaed5635997fc39c8c154bac::getLoader();
     25return ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3::getLoader();
  • linguise/tags/2.2.21/vendor/composer/autoload_real.php

    r3425738 r3454249  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit7960a36ebaed5635997fc39c8c154bac
     5class ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInit7960a36ebaed5635997fc39c8c154bac', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInit7960a36ebaed5635997fc39c8c154bac', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInitc42aec6a4150974a31712053598e6fb3::getInitializer($loader));
    3131
    3232        $loader->register(true);
    3333
    34         $filesToLoad = \Composer\Autoload\ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::$files;
     34        $filesToLoad = \Composer\Autoload\ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$files;
    3535        $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
    3636            if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • linguise/tags/2.2.21/vendor/composer/autoload_static.php

    r3425738 r3454249  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit7960a36ebaed5635997fc39c8c154bac
     7class ComposerStaticInitc42aec6a4150974a31712053598e6fb3
    88{
    99    public static $files = array (
     
    156156    {
    157157        return \Closure::bind(function () use ($loader) {
    158             $loader->prefixLengthsPsr4 = ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::$prefixLengthsPsr4;
    159             $loader->prefixDirsPsr4 = ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::$prefixDirsPsr4;
    160             $loader->classMap = ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::$classMap;
     158            $loader->prefixLengthsPsr4 = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$prefixLengthsPsr4;
     159            $loader->prefixDirsPsr4 = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$prefixDirsPsr4;
     160            $loader->classMap = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$classMap;
    161161
    162162        }, null, ClassLoader::class);
  • linguise/tags/2.2.21/vendor/composer/installed.php

    r3442930 r3454249  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => '354f19240a11160636da0632f88c9c6f875a58b2',
     6        'reference' => '4be8301399bf629dadffa1fbb936c0a2eabc3874',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    3232            'pretty_version' => 'dev-master',
    3333            'version' => 'dev-master',
    34             'reference' => '354f19240a11160636da0632f88c9c6f875a58b2',
     34            'reference' => '4be8301399bf629dadffa1fbb936c0a2eabc3874',
    3535            'type' => 'library',
    3636            'install_path' => __DIR__ . '/../../',
  • linguise/trunk/composer.json

    r3430418 r3454249  
    3636    "phpunit/php-code-coverage": "9.2.32",
    3737    "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"
    3940  },
    4041  "repositories": [
  • linguise/trunk/linguise.php

    r3442930 r3454249  
    55 * Plugin URI: https://www.linguise.com/
    66 * Description: Linguise translation plugin
    7  * Version:2.2.20
     7 * Version:2.2.21
    88 * Text Domain: linguise
    99 * Domain Path: /languages
     
    478478        if (strpos(file_get_contents($htaccess_file), 'BEGIN GTranslate config') !== false) {
    479479            echo '<div class="error">';
     480            /* translators: %1$s: GTranslate %2$s: GTranslate */
    480481            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>';
    481482            echo '</div>';
  • linguise/trunk/readme.txt

    r3442930 r3454249  
    44Requires at least: 4.0
    55Tested up to: 6.9
    6 Stable tag: 2.2.20
     6Stable tag: 2.2.21
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    108108
    109109== Changelog ==
     110= 2.2.21 =
     111- Feature: Support more languages for admin dashboard
     112
    110113= 2.2.20 =
    111114- Feature: Support translating WPForms redirect URL
  • linguise/trunk/src/AttributeHandler.php

    r3397694 r3454249  
    6868        }
    6969
    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);
    7371
    7472        // loop through the list and add extra field, use reference
     
    171169        $html_dom = HTMLHelper::loadHTML($html_data);
    172170        if (empty($html_dom)) {
    173             return [];
     171            return []; // @codeCoverageIgnore
    174172        }
    175173
     
    182180        foreach ($elements as $element) {
    183181            if ($element->nodeType !== XML_ELEMENT_NODE) {
    184                 continue;
     182                continue; // @codeCoverageIgnore
    185183            }
    186184
     
    282280        foreach ($elements as $element) {
    283281            if ($element->nodeType !== XML_ELEMENT_NODE) {
    284                 continue;
     282                continue; // @codeCoverageIgnore
    285283            }
    286284
     
    308306        $html_dom = HTMLHelper::loadHTML($html_data);
    309307        if (empty($html_dom)) {
    310             return $html_data;
     308            return $html_data; // @codeCoverageIgnore
    311309        }
    312310
     
    340338                $match_data = $attr_html->getAttribute($matched['key']);
    341339                if (empty($match_data)) {
    342                     continue;
     340                    continue; // @codeCoverageIgnore
    343341                }
    344342
     
    361359                    $first_value = isset($first_fragment['value']) ? $first_fragment['value'] : null;
    362360                    if (empty($first_value)) {
    363                         continue;
     361                        continue; // @codeCoverageIgnore
    364362                    }
    365363
     
    375373                    $first_fragment = isset($fragment_list['fragments'][0]) ? $fragment_list['fragments'][0] : null;
    376374                    if (empty($first_fragment)) {
    377                         continue;
     375                        continue; // @codeCoverageIgnore
    378376                    }
    379377
    380378                    $first_value = isset($first_fragment['value']) ? $first_fragment['value'] : null;
    381379                    if (empty($first_value)) {
    382                         continue;
     380                        continue; // @codeCoverageIgnore
    383381                    }
    384382
     
    402400                        try {
    403401                            $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
    406404                        }
    407405                    }
  • linguise/trunk/src/FragmentBase.php

    r3414869 r3454249  
    225225        // Run through filters, provide our current default filters
    226226        // 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);
    234228
    235229        // cache the list
     
    493487
    494488    /**
     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    /**
    495507     * Get override JSON fragment matching
    496508     *
     
    607619
    608620        // 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);
    614622
    615623        return $current_list;
  • linguise/trunk/src/FragmentHandler.php

    r3428799 r3454249  
    66use Linguise\WordPress\Helper;
    77use Linguise\WordPress\HTMLHelper;
    8 use Linguise\Vendor\JsonPath\JsonObject;
    98use Linguise\Vendor\Linguise\Script\Core\Debug;
    109
    1110defined('ABSPATH') || die('');
     11
     12require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentOverrideHandler.php';
     13require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentAutoHandler.php';
     14require_once __DIR__ . DIRECTORY_SEPARATOR . 'FragmentI18nHandler.php';
    1215
    1316/**
     
    148151            return $result;
    149152        }
    150         return $text;
     153        return $text; // @codeCoverageIgnore
    151154    }
    152155
     
    165168            return $result;
    166169        }
    167         return $text;
     170        return $text; // @codeCoverageIgnore
    168171    }
    169172
     
    331334    private static function tryMatchWithOverride($script, $html_data)
    332335    {
    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);
    402337    }
    403338
     
    411346    public static function tryMatchTranslationBlock($script)
    412347    {
    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);
    466349    }
    467350
     
    478361        $html_dom = HTMLHelper::loadHTML($html_data);
    479362        if (empty($html_dom)) {
    480             return [];
     363            return []; // @codeCoverageIgnore
    481364        }
    482365
     
    585468    public static function applyTranslatedFragmentsForOverride($html_data, $fragment_name, $fragment_param, $fragment_info)
    586469    {
    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);
    683471    }
    684472
     
    693481    public static function applyTranslatedFragmentsForAuto($json_data, $fragments)
    694482    {
    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);
    717484    }
    718485
     
    729496    public static function applyTranslatedFragmentsForI18n($html_data, $param_name, $param_key, $fragments)
    730497    {
    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);
    814499    }
    815500
     
    865550                $replaced_json = self::applyTranslatedFragmentsForAuto(json_decode('{' . $html_matches[3] . '}', true), $fragment_list['fragments']);
    866551
    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);
    870553
    871554                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
    873556                }
    874557
  • linguise/trunk/src/config-iframe.php

    r3430418 r3454249  
    88            'message' => __('Nonce verification failed', 'linguise')
    99        ));
     10        return;
    1011    }
    1112
     
    1617            'message' => __('User is not logged in', 'linguise')
    1718        ));
     19        return;
    1820    }
    1921    // check if user has permission to manage options
     
    2325            'message' => __('User does not have permission to manage options', 'linguise')
    2426        ));
     27        return;
    2528    }
    2629
     
    3134            'message' => __('No data to update', 'linguise')
    3235        ));
     36        return;
    3337    }
    3438
     
    5357                )
    5458            ));
     59            return;
    5560        }
    5661    }
     
    102107            'back_link' => true,
    103108        ));
     109        return;
    104110    }
    105111
     
    111117            'back_link' => true,
    112118        ));
     119        return;
    113120    }
    114121    // check if user has permission to manage options
     
    119126            'back_link' => true,
    120127        ));
     128        return;
    121129    }
    122130
  • linguise/trunk/src/constants.php

    r3442930 r3454249  
    11<?php
    22if (!defined('LINGUISE_SCRIPT_TRANSLATION_VERSION')) {
    3     define('LINGUISE_SCRIPT_TRANSLATION_VERSION', 'wordpress_plugin/2.2.20');
     3    define('LINGUISE_SCRIPT_TRANSLATION_VERSION', 'wordpress_plugin/2.2.21');
    44}
    55
    66if (!defined('LINGUISE_VERSION')) {
    7     define('LINGUISE_VERSION', '2.2.20');
     7    define('LINGUISE_VERSION', '2.2.21');
    88}
  • linguise/trunk/src/thirdparty/ajax-search-lite.php

    r3425738 r3454249  
    8686     * Unload the integration
    8787     *
     88     * @codeCoverageIgnore
     89     *
    8890     * @return void
    8991     */
    9092    public function destroy()
    9193    {
    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);
    9597
    9698        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No action
    9799        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);
    99101        }
    100102    }
     
    159161            $query_args['s'] = $translated_query;
    160162        }
    161        
     163
    162164        return $query_args;
    163165    }
     
    195197    public function addHtmlAttribute($tag, $handle, $src)
    196198    {
    197 
    198199        if (is_plugin_active('litespeed-cache/litespeed-cache.php')) {
    199200            if ($handle === 'wd-asl-ajaxsearchlite') {
     
    215216    public function translateAjaxResult($html_result)
    216217    {
    217 
    218218        $language = WPHelper::getLanguageFromReferer();
    219219
     
    242242        if (!$matches) {
    243243            // No body match
    244             return $html_result;
     244            return $html_result; // @codeCoverageIgnore
    245245        }
    246246
  • linguise/trunk/src/thirdparty/surecart.php

    r3339453 r3454249  
    354354            $contexts[] = [
    355355                'context' => $match[0],
    356                 'data' => json_decode('{' . $match[1] . '}'),
     356                'data' => json_decode('{' . $match[1] . '}', true),
    357357            ];
    358358        }
     
    368368            $context = $contexts[$index];
    369369            if (empty($context['data'])) {
    370                 continue;
     370                continue; // @codeCoverageIgnore
    371371            }
    372372            $fragments = FragmentHandler::collectFragmentFromJson($context['data']);
     
    418418            $index = (int)str_replace('index-', '', $key_prefix);
    419419            // Find the context
    420             $context = $contexts[$index];
    421             if (empty($context)) {
     420            if (!isset($contexts[$index]) || empty($contexts[$index])) {
    422421                continue;
    423422            }
     423            $context = $contexts[$index];
    424424
    425425            $tl_json_frag_list = $tl_json_frag['fragments'];
    426426            if (empty($tl_json_frag_list)) {
    427                 continue;
     427                continue; // @codeCoverageIgnore
    428428            }
    429429
     
    462462            return $repl_block_content;
    463463        }
    464         return $block_content;
     464        return $block_content; // @codeCoverageIgnore
    465465    }
    466466
  • linguise/trunk/vendor/autoload.php

    r3425738 r3454249  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInit7960a36ebaed5635997fc39c8c154bac::getLoader();
     25return ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3::getLoader();
  • linguise/trunk/vendor/composer/autoload_real.php

    r3425738 r3454249  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit7960a36ebaed5635997fc39c8c154bac
     5class ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInit7960a36ebaed5635997fc39c8c154bac', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInit7960a36ebaed5635997fc39c8c154bac', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitc42aec6a4150974a31712053598e6fb3', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInitc42aec6a4150974a31712053598e6fb3::getInitializer($loader));
    3131
    3232        $loader->register(true);
    3333
    34         $filesToLoad = \Composer\Autoload\ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::$files;
     34        $filesToLoad = \Composer\Autoload\ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$files;
    3535        $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
    3636            if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • linguise/trunk/vendor/composer/autoload_static.php

    r3425738 r3454249  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit7960a36ebaed5635997fc39c8c154bac
     7class ComposerStaticInitc42aec6a4150974a31712053598e6fb3
    88{
    99    public static $files = array (
     
    156156    {
    157157        return \Closure::bind(function () use ($loader) {
    158             $loader->prefixLengthsPsr4 = ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::$prefixLengthsPsr4;
    159             $loader->prefixDirsPsr4 = ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::$prefixDirsPsr4;
    160             $loader->classMap = ComposerStaticInit7960a36ebaed5635997fc39c8c154bac::$classMap;
     158            $loader->prefixLengthsPsr4 = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$prefixLengthsPsr4;
     159            $loader->prefixDirsPsr4 = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$prefixDirsPsr4;
     160            $loader->classMap = ComposerStaticInitc42aec6a4150974a31712053598e6fb3::$classMap;
    161161
    162162        }, null, ClassLoader::class);
  • linguise/trunk/vendor/composer/installed.php

    r3442930 r3454249  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => '354f19240a11160636da0632f88c9c6f875a58b2',
     6        'reference' => '4be8301399bf629dadffa1fbb936c0a2eabc3874',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    3232            'pretty_version' => 'dev-master',
    3333            'version' => 'dev-master',
    34             'reference' => '354f19240a11160636da0632f88c9c6f875a58b2',
     34            'reference' => '4be8301399bf629dadffa1fbb936c0a2eabc3874',
    3535            'type' => 'library',
    3636            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.