Plugin Directory

Changeset 2928790


Ignore:
Timestamp:
06/20/2023 06:43:31 PM (3 years ago)
Author:
pluginsclub
Message:

fixed bug with Cyrillic text in Gutenberg block and CSS issue reported by @bsmolyanov

Location:
diff-check/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • diff-check/trunk/README.txt

    r2878497 r2928790  
    55Tested up to: 6.1
    66Requires PHP: 5.4
    7 Stable tag: 1.1
    8 Donate link: https://plugins.club/wordpress/diff-check/
     7Stable tag: 1.2
     8Donate link: https://plugins.club/free-wordpress-plugins/diff-check/
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3636== Changelog ==
    3737
     38= 1.2 =
     39* Added support for Cyrillic in gutenberg block - reported by @bsmolyanov
     40* Fixed CSS issue with wrong class names - reported by @bsmolyanov
     41* Added CSS to style the rows that have no diff
     42
    3843= 1.1 =
    3944* Added gutenberg block
  • diff-check/trunk/diff_check.php

    r2878471 r2928790  
    22/*
    33Plugin Name: Diff Check
    4 Plugin URI: https://plugins.club/wordpress/diff-check/
     4Plugin URI: https://plugins.club/free-wordpress-plugins/diff-check/
    55Description: Display a side-by-side comparison of two texts or files.
    6 Version: 1.1
     6Version: 1.2
    77Author: plugins.club
    88Author URI: https://plugins.club
     
    1010
    1111function diff_check_scripts() {
    12     wp_enqueue_script( 'diff_check', plugin_dir_url( __FILE__ ) . 'includes/js/diff_check.js', array(), '1.0.0', true );
    13     wp_enqueue_style( 'diff_check', plugin_dir_url( __FILE__ ) . 'includes/css/diff_check.css', array(), '1.0.0' );
     12    wp_enqueue_script( 'diff_check', plugin_dir_url( __FILE__ ) . 'includes/js/diff_check.js', array(), '1.0.1', true );
     13    wp_enqueue_style( 'diff_check', plugin_dir_url( __FILE__ ) . 'includes/css/diff_check.css', array(), '1.0.3' );
    1414wp_enqueue_script( 'diff_check', plugin_dir_url( __FILE__ ) . 'includes/js/diff_check.js', array( 'wp-blocks', 'wp-editor', 'wp-element' ), '1.0.0', true );
    1515wp_enqueue_script( 'diff_check_block', plugin_dir_url( __FILE__ ) . 'includes/js/diff_check_block.js', array( 'wp-blocks', 'wp-editor', 'wp-element' ), '1.0.0', true );
  • diff-check/trunk/includes/css/diff_check.css

    r2878334 r2928790  
    1 #diff-check-output {
    2     padding: 10px;
     1.diff-check {
    32}
    43
    5 #diff-check-output del {
     4.diff-check del {
    65    background-color: #fcf0f1;
    76}
    87
    9 #diff-check-output ins {
     8.diff-check ins {
    109    background-color: #edfaef;
    1110}
     11
     12.td.diff-deletedline, .td.diff-addedline {
     13     /* Remove the border */
     14}
     15
     16table.diff.is-split-view {
     17table-layout: fixed;
     18width: 100%;
     19white-space: pre-wrap;
     20margin: 0px;
     21}
  • diff-check/trunk/includes/css/diff_check_frontend.css

    r2878471 r2928790  
    1 #diff-check-output del {
     1.diff-check del {
    22    background-color: #fcf0f1;
    33}
    44
    5 #diff-check-output ins {
     5.diff-check ins {
    66    background-color: #edfaef;
    77}
     8
     9.diff-check-table .diff-context:nth-child(odd) {
     10  margin-right: 10px;
     11}
     12
     13.diff-check-table .diff-context:nth-child(even) {
     14  margin-left: 10px;
     15}
  • diff-check/trunk/includes/gutenberg-block.php

    r2878471 r2928790  
    11<?php
    22
    3 //Gutenberg block
     3// Gutenberg block
    44function diff_check_register_block() {
    5     if ( ! function_exists( 'register_block_type' ) ) {
     5    if (!function_exists('register_block_type')) {
    66        return;
    77    }
     
    1212    wp_register_script(
    1313        $block_script_handle,
    14         plugin_dir_url( __FILE__ ) . 'js/diff_check_block.js',
    15         array( 'wp-blocks', 'wp-element', 'wp-editor' ),
    16         filemtime( plugin_dir_path( __FILE__ ) . 'js/diff_check_block.js' )
     14        plugin_dir_url(__FILE__) . 'js/diff_check_block.js',
     15        array('wp-blocks', 'wp-element', 'wp-editor'),
     16        filemtime(plugin_dir_path(__FILE__) . 'js/diff_check_block.js')
    1717    );
    1818    wp_register_style(
    1919        $block_style_handle,
    20         plugin_dir_url( __FILE__ ) . 'css/diff_check_block.css',
    21         array( ),
    22         filemtime( plugin_dir_path( __FILE__ ) . 'css/diff_check_block.css' )
     20        plugin_dir_url(__FILE__) . 'css/diff_check_block.css',
     21        array(),
     22        filemtime(plugin_dir_path(__FILE__) . 'css/diff_check_block.css')
    2323    );
    24     register_block_type( $block_name, array(
     24    register_block_type($block_name, array(
    2525        'editor_script' => $block_script_handle,
    2626        'editor_style' => $block_style_handle,
     
    4444            ),
    4545        ),
    46     ) );
     46    ));
    4747}
    48 add_action( 'init', 'diff_check_register_block' );
     48add_action('init', 'diff_check_register_block');
    4949
    50 function diff_check_block_render( $attributes ) {
     50function diff_check_block_render($attributes) {
    5151    $text1 = $attributes['text1'];
    5252    $text2 = $attributes['text2'];
    5353
    54     if ( $attributes['file1'] != '' ) {
    55         $text1 = file_get_contents( $attributes['file1'] );
     54    if ($attributes['file1'] != '') {
     55        $text1 = file_get_contents($attributes['file1']);
    5656    }
    5757
    58     if ( $attributes['file2'] != '' ) {
    59         $text2 = file_get_contents( $attributes['file2'] );
     58    if ($attributes['file2'] != '') {
     59        $text2 = file_get_contents($attributes['file2']);
    6060    }
    6161
    62     $diff = wp_text_diff( $text1, $text2 );
    63     $differences_count = substr_count( $diff, '<ins>' ) + substr_count( $diff, '<del>' );
     62    // Convert texts to arrays of rows
     63    $rows1 = explode("\n", $text1);
     64    $rows2 = explode("\n", $text2);
     65
     66    // Calculate the diff row by row
     67    $diff = '';
     68    $differences_count = 0;
     69
     70    $numRows1 = count($rows1);
     71    $numRows2 = count($rows2);
     72    $numRows = max($numRows1, $numRows2);
     73
     74    $diff .= '<table class="diff-check-table">';
     75
     76    for ($i = 0; $i < $numRows; $i++) {
     77        $row1 = isset($rows1[$i]) ? $rows1[$i] : '';
     78        $row2 = isset($rows2[$i]) ? $rows2[$i] : '';
     79
     80        $row1 = htmlspecialchars($row1, ENT_QUOTES | ENT_HTML5, 'UTF-8');
     81        $row2 = htmlspecialchars($row2, ENT_QUOTES | ENT_HTML5, 'UTF-8');
     82
     83        $rowDiff = wp_text_diff($row1, $row2);
     84
     85        // Handle rows with no differences in both text1 and text2
     86        if ($rowDiff === '') {
     87            // Add the structure to rows with no differences
     88        $rowDiff = '<table class="diff is-split-view"><tbody><tr><td class="diff-deletedline"><span aria-hidden="true" class="dashicons arrow-right-alt2"></span>' . $row1 . '</td><td class="diff-deletedline"><span aria-hidden="true" class="dashicons arrow-right"></span>' . $row2 . '</td></tr></td></tr></tbody></table>';
     89        } else {
     90            // Add the structure to rows with differences
     91            $rowDiff = '<tr>' . $rowDiff . '</tr>';
     92        }
     93
     94        // Count differences
     95        if ($rowDiff !== '') {
     96            $differences_count++;
     97        }
     98
     99        $diff .= $rowDiff;
     100    }
     101
     102    $diff .= '</table>';
    64103
    65104    return '<div class="diff-check">' . $diff . '</div><p>Differences found: ' . $differences_count . '</p>';
  • diff-check/trunk/includes/shortcodes.php

    r2878471 r2928790  
    2121    }
    2222
    23     $diff = wp_text_diff( $text1, $text2 );
     23    // Convert text to HTML entities
     24    $text1_entities = htmlentities($text1, ENT_COMPAT | ENT_HTML401, 'UTF-8');
     25    $text2_entities = htmlentities($text2, ENT_COMPAT | ENT_HTML401, 'UTF-8');
     26
     27    // Generate the text diff using HTML entities
     28    $diff = wp_text_diff( $text1_entities, $text2_entities );
     29
     30    // Replace HTML entities with human-readable Cyrillic characters
     31    $diff = html_entity_decode($diff, ENT_COMPAT | ENT_HTML401, 'UTF-8');
     32
     33    // Count the differences
    2434    $differences_count = substr_count($diff,'<ins>') + substr_count($diff,'<del>');
    2535
Note: See TracChangeset for help on using the changeset viewer.