Plugin Directory

Changeset 3148988


Ignore:
Timestamp:
09/10/2024 05:07:54 AM (7 months ago)
Author:
mvpis
Message:

Many performance improvements, enhanced user interface and streamlined signup flow

Location:
fluentc-translation
Files:
365 added
10 edited

Legend:

Unmodified
Added
Removed
  • fluentc-translation/trunk/bootstrap.php

    r3135855 r3148988  
    6262            'FluentC\Actions\Wordpress',
    6363            'FluentC\Actions\Admin',
     64            'FluentC\Actions\Siteorigin',
    6465            'FluentC\Actions\Translationstatus',
    6566        );
  • fluentc-translation/trunk/fluentc_settings.php

    r3135855 r3148988  
    3030        <p><?php _e( 'To use FluentC, you need an active subscription.', 'fluentc-translation' ); ?></p>
    3131        <?php if ( $this->fluentc_get_settings() ) { ?>
    32             <a href="https://dashboard.fluentc.ai/manage/<?php echo esc_attr( $this->fluentc_get_settings() ); ?>?redirect=<?php echo esc_url( admin_url( 'admin.php?page=fluentc-settings' ) ); ?>" class="button button-primary"><?php _e( 'Manage FluentC Account and Languages', 'fluentc-translation' ); ?></a>
     32            <a href="https://dashboard.fluentc.ai/manage/<?php echo esc_attr( $this->fluentc_get_settings() ); ?>?redirect=<?php echo esc_url( admin_url( 'admin.php?page=fluentc-settings' ) ); ?>" class="button button-primary"><?php _e( 'Manage FluentC Account and Add Languages', 'fluentc-translation' ); ?></a>
    3333        <?php } else { ?>
    3434            <a href="https://dashboard.fluentc.ai/sites?instruction=connect&redirect=<?php echo esc_url( admin_url( 'admin.php?page=fluentc-settings' ) ); ?>" class="button button-primary"><?php _e( 'Sign Up and Connect to FluentC', 'fluentc-translation' ); ?></a>
     
    4444    <div id="tab-2" class="tab-content">
    4545        <?php do_action( 'fluentc_admin_settings_page' ); ?>
     46        <div class="fluentc-header-button">
     47            <?php if ( $this->fluentc_get_settings() ) { ?>
     48                <a href="https://dashboard.fluentc.ai/manage/<?php echo esc_attr( $this->fluentc_get_settings() ); ?>?redirect=<?php echo esc_url( admin_url( 'admin.php?page=fluentc-settings' ) ); ?>" class="button button-primary"><?php _e( 'Add Languages in FluentC Dashboard', 'fluentc-translation' ); ?></a>
     49            <?php } else { ?>
     50                <a href="https://dashboard.fluentc.ai/sites?instruction=connect&redirect=<?php echo esc_url( admin_url( 'admin.php?page=fluentc-settings' ) ); ?>" class="button button-primary"><?php _e( 'Add Languages in FluentC Dashboard', 'fluentc-translation' ); ?></a>
     51            <?php } ?>
     52        </div>
    4653    </div>
    4754
  • fluentc-translation/trunk/fluentc_wordpress_plugin.php

    r3148368 r3148988  
    77 * Plugin URI: https://github.com/fluentc/wordpress-plugin
    88 * Description: A plugin that enables website owners to easily install the FluentC Translation on their WordPress site.
    9  * Version: 1.7.4
     9 * Version: 1.8
    1010 * Author: FluentC
    1111 * Author URI: https://www.fluentc.ai
     
    1717define( 'FLUENTC_DIR', __DIR__ );
    1818define( 'FLUENTC_SLUG', 'fluentc_translation' );
    19 define( 'FLUENTC_TRANSLATION_VERSION', "1.7.4" );
     19define( 'FLUENTC_TRANSLATION_VERSION', "1.8" );
    2020define( 'FLUENTC_TRANSLATION_PLUGIN_DIR', plugin_dir_path(__FILE__) );
    2121define( 'FLUENTC_TRANSLATION_PLUGIN_URL', plugin_dir_url(__FILE__) );
  • fluentc-translation/trunk/readme.txt

    r3148368 r3148988  
    55Requires at least: 4.6
    66Tested up to: 6.6.1
    7 Stable tag: 1.7.4
     7Stable tag: 1.8
    88Requires PHP: 7.3
    99License: GPLv2 or later
  • fluentc-translation/trunk/src/actions/class-admin.php

    r3135855 r3148988  
    116116     */
    117117    public function fluentc_sub_menu() {
    118         add_submenu_page('fluentc-settings', 'Manage Translations', 'Manage Translations', 'manage_options', 'fluentc-manage-translations', array($this->translations, 'display_translations_page'));
     118        add_submenu_page('fluentc-settings', 'Edit Translations', 'Edit Translations', 'manage_options', 'fluentc-manage-translations', array($this->translations, 'display_translations_page'));
    119119    }
    120120
     
    136136            $this->fluentc_cache->clean();
    137137            wp_safe_redirect( admin_url( 'admin.php?page=fluentc-settings' ) );
     138            exit;
    138139        }
    139140    }
     
    169170            try {
    170171                $this->fluentc_cache->clean();
     172                do_action( 'fluentc_admin_clean_cache' );
    171173                wp_safe_redirect( admin_url( 'admin.php?page=fluentc-settings' ) );
    172                 do_action( 'fluentc_admin_clean_cache' );
    173174                exit;
    174175            } catch ( \Exception $e ) {
     
    368369        if ( $languages ) {
    369370            wp_safe_redirect( admin_url( 'admin.php?page=fluentc-settings' ) );
     371            exit;
    370372        } else {
    371373            echo esc_html( '<strong>Widget has no languages setup, please visit FluentC and enable a language to translate</strong>' );
  • fluentc-translation/trunk/src/actions/class-translationstatus.php

    r3135855 r3148988  
    6565     */
    6666    public function hooks() {
    67         add_action('admin_menu', [$this, 'addTranslationStatusSubMenu']);
     67        //add_action('admin_menu', [$this, 'addTranslationStatusSubMenu']);
    6868        add_action('admin_enqueue_scripts', [$this, 'enqueueAssets']);
    6969        add_action('wp_ajax_fluentc_scan_site', [$this, 'ajaxScanSite']);
  • fluentc-translation/trunk/src/actions/class-wordpress.php

    r3147335 r3148988  
    162162    $entry_skip_map = [];
    163163
    164     $elements = $dom->find('*:not(script):not(style):not(code):not(figure):not(pre):not(noscript):not(iframe):not(object):not(embed):not(svg):not(math):not(canvas)');
     164    $elements = $dom->find('*:not(script):not(style):not(doctype):not(code):not(figure):not(pre):not(noscript):not(iframe):not(object):not(embed):not(svg):not(math):not(canvas)');
    165165    foreach ($elements as $element) {
    166166        $nodes = ($element instanceof \PHPHtmlParser\Dom\Node\HtmlNode) ? $element->getChildren() : [$element];
     
    270270        return;
    271271    }
     272    if ( in_array($text, $this->fluentc_htmltags->forbidden_selectors) ) {
     273        // Skip or delete the DOCTYPE node
     274        $node->setText('');
     275        return;
     276    }
    272277   
    273278    $key = hash('md5', $text);
     
    340345    $entry_skip_map = [];
    341346
    342     $elements = $dom->find('*:not(script):not(style):not(code):not(figure):not(pre):not(noscript):not(iframe):not(object):not(embed):not(svg):not(math):not(canvas)');
     347    $elements = $dom->find('*:not(script):not(style):not(code):not(doctype):not(figure):not(pre):not(noscript):not(iframe):not(object):not(embed):not(svg):not(math):not(canvas)');
    343348    foreach ($elements as $element) {
    344349        $nodes = ($element instanceof \PHPHtmlParser\Dom\Node\HtmlNode) ? $element->getChildren() : [$element];
     
    482487        $widgetapikey  = get_option( 'fluentc_api_key' );
    483488       
    484         if ( $language_code ) {
    485             // If language code is set, modify the output accordingly.
    486             $html = $this->fluentc_connenct->get_translation_content( $widgetapikey, $this->site_language, $language_code, $text );
    487             return $this->fluentc_html->find_and_replace( $text, $html, $language_code, $this->fluentc_connenct->get_language_list_string( $widgetapikey ) );
     489        if ( !$widgetapikey ) {
     490            return $text;
     491        }
     492       
     493        if (!$language_code || is_null($text) || $text === '') {
     494            return $text;
     495        }
     496
     497        if ( function_exists( 'wc_get_page_id' ) ) {
     498            if ( is_page( wc_get_page_id( 'checkout' ) ) || is_page( wc_get_page_id( 'cart' ) ) ) {
     499                return $text;
     500            }
     501        }
     502
     503        $html = html_entity_decode($text, ENT_QUOTES | ENT_XML1, 'UTF-8');
     504   
     505        if (empty($html)) {
     506            return $text;
     507        }
     508   
     509        $options = new Options();
     510        $options->setCleanupInput(false);
     511        $options->setWhitespaceTextNode(false);
     512   
     513        $dom = new Dom;
     514        $dom->loadStr($html, $options);
     515   
     516        $texts_to_translate = [];
     517        $entry_map = [];
     518        $entry_skip_map = [];
     519   
     520        $elements = $dom->find('*:not(script):not(style):not(code):not(doctype):not(figure):not(pre):not(noscript):not(iframe):not(object):not(embed):not(svg):not(math):not(canvas)');
     521        foreach ($elements as $element) {
     522            $nodes = ($element instanceof \PHPHtmlParser\Dom\Node\HtmlNode) ? $element->getChildren() : [$element];
     523            foreach ($nodes as $node) {
     524                $this->processNode($node, $texts_to_translate, $entry_map, $entry_skip_map);
     525            }
     526        }
     527   
     528        if (!empty($texts_to_translate)) {
     529            $uncached_texts = [];
     530            $cached_translations = [];
     531   
     532            foreach ($texts_to_translate as $node_text) {
     533                $key = hash('md5', $node_text);
     534                $cache_key = $this->site_language . $language_code . $key;
     535                $cached_translation = $this->fluentc_cache->get($cache_key);
     536   
     537                if ($cached_translation) {
     538                    $json_cache = json_decode($cached_translation);
     539                    if (isset($json_cache->data->translateSite->body)) {
     540                        $cached_translations[] = $json_cache->data->translateSite->body;
     541                    }
     542                } else {
     543                    $uncached_texts[] = $node_text;
     544                }
     545            }
     546   
     547            if (!empty($uncached_texts)) {
     548                $text_labels = $this->process_text_labels($uncached_texts);
     549   
     550                $translated_texts = $this->fluentc_connenct->get_translation_content(
     551                    $this->widgetapikey,
     552                    $this->site_language,
     553                    $language_code,
     554                    $text_labels
     555                );
     556   
     557                if (isset($translated_texts->data->translateSite->body) && !empty($translated_texts->data->translateSite->body)) {
     558                    $cached_translations = array_merge($cached_translations, $translated_texts->data->translateSite->body);
     559                } else {
     560                    do_action('qm/debug', 'Translation error: Data not found in response.');
     561                }
     562            }
     563   
     564            $this->applyTranslations($entry_map, $cached_translations, $language_code);
    488565        } else {
    489             // If no language code, return the default output.
    490             return $text;
    491         }
     566           // do_action('qm/info', 'No translation needed.');
     567        }
     568   
     569        $this->applySkippedTranslations($entry_skip_map);
     570   
     571        $html = $dom->root->innerHtml();
     572        $html = $this->fluentc_html->find_and_replace($html, null, $language_code, $this->fluentc_connenct->get_language_list_string($this->widgetapikey));
     573        return $html;
    492574    }
    493575
  • fluentc-translation/trunk/src/models/class-htmltags.php

    r3122693 r3148988  
    3232     */
    3333    public $forbidden_selectors = array(
    34         'link',
    35         'script',
    36         'style',
    37         'kbd',
    38         '._fluentc_widget-language-dropdown',
     34        'W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> ',
    3935        '._fluentc_widget-language-manager',
    4036        '._fluentc_widget-language-list',
    4137        '._fluentc_widget_float_dropdown_wrapper',
    42         'noscript',
    4338    );
    4439
  • fluentc-translation/trunk/src/services/class-connect.php

    r3148368 r3148988  
    132132        $widgetapikey = get_option( 'fluentc_api_key' );
    133133        if ( !$widgetapikey ) {
    134             return array(); // Return nothing if the API key is not set
     134            return; // Return nothing if the API key is not set
    135135        }
    136136   
  • fluentc-translation/trunk/vendor/paquettg/string-encode/src/stringEncode/Encode.php

    r3129167 r3148988  
    9191     * @return string
    9292     */
    93     public  function convert($str)
    94     {
    95         if ($this->from != $this->to)
    96         {
    97             $str = iconv($this->from, $this->to, $str);
    98         }
     93    public function convert($str)
     94{
     95    // Ensure $str is not null or false before processing
     96    if (!is_string($str) || $str === null) {
     97        throw new Exception('Input string is null or invalid.');
     98    }
    9999
    100         if ($str === false)
    101         {
    102             // the convertion was a failure
    103             throw new Exception('The convertion from "'.$this->from.'" to "'.$this->to.'" was a failure.');
    104         }
     100    if ($this->from != $this->to) {
     101        $str = iconv($this->from, $this->to, $str);
     102    }
    105103
    106         // deal with BOM issue for utf-8 text
    107         if ($this->to == 'UTF-8')
    108         {
    109             if (substr($str, 0, 3) == "\xef\xbb\xbf")
    110             {
    111                 $str = substr($str, 3);
    112             }
    113             if (substr($str, -3, 3) == "\xef\xbb\xbf")
    114             {
    115                 $str = substr($str, 0, -3);
    116             }
    117         }
     104    if ($str === false) {
     105        // The conversion was a failure
     106        throw new Exception('The conversion from "' . $this->from . '" to "' . $this->to . '" was a failure.');
     107    }
    118108
    119         return $str;
    120     }
     109    // Deal with BOM issue for utf-8 text
     110    if ($this->to == 'UTF-8' && is_string($str)) {
     111        if (substr($str, 0, 3) == "\xef\xbb\xbf") {
     112            $str = substr($str, 3);
     113        }
     114        if (substr($str, -3, 3) == "\xef\xbb\xbf") {
     115            $str = substr($str, 0, -3);
     116        }
     117    }
     118
     119    return $str;
    121120}
     121}
Note: See TracChangeset for help on using the changeset viewer.