Changeset 2928790
- Timestamp:
- 06/20/2023 06:43:31 PM (3 years ago)
- Location:
- diff-check/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (2 diffs)
-
diff_check.php (modified) (2 diffs)
-
includes/css/diff_check.css (modified) (1 diff)
-
includes/css/diff_check_frontend.css (modified) (1 diff)
-
includes/gutenberg-block.php (modified) (3 diffs)
-
includes/shortcodes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
diff-check/trunk/README.txt
r2878497 r2928790 5 5 Tested up to: 6.1 6 6 Requires PHP: 5.4 7 Stable tag: 1. 18 Donate link: https://plugins.club/ wordpress/diff-check/7 Stable tag: 1.2 8 Donate link: https://plugins.club/free-wordpress-plugins/diff-check/ 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 36 36 == Changelog == 37 37 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 38 43 = 1.1 = 39 44 * Added gutenberg block -
diff-check/trunk/diff_check.php
r2878471 r2928790 2 2 /* 3 3 Plugin Name: Diff Check 4 Plugin URI: https://plugins.club/ wordpress/diff-check/4 Plugin URI: https://plugins.club/free-wordpress-plugins/diff-check/ 5 5 Description: Display a side-by-side comparison of two texts or files. 6 Version: 1. 16 Version: 1.2 7 7 Author: plugins.club 8 8 Author URI: https://plugins.club … … 10 10 11 11 function 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' ); 14 14 wp_enqueue_script( 'diff_check', plugin_dir_url( __FILE__ ) . 'includes/js/diff_check.js', array( 'wp-blocks', 'wp-editor', 'wp-element' ), '1.0.0', true ); 15 15 wp_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 { 3 2 } 4 3 5 #diff-check-outputdel {4 .diff-check del { 6 5 background-color: #fcf0f1; 7 6 } 8 7 9 #diff-check-outputins {8 .diff-check ins { 10 9 background-color: #edfaef; 11 10 } 11 12 .td.diff-deletedline, .td.diff-addedline { 13 /* Remove the border */ 14 } 15 16 table.diff.is-split-view { 17 table-layout: fixed; 18 width: 100%; 19 white-space: pre-wrap; 20 margin: 0px; 21 } -
diff-check/trunk/includes/css/diff_check_frontend.css
r2878471 r2928790 1 #diff-check-outputdel {1 .diff-check del { 2 2 background-color: #fcf0f1; 3 3 } 4 4 5 #diff-check-outputins {5 .diff-check ins { 6 6 background-color: #edfaef; 7 7 } 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 1 1 <?php 2 2 3 // Gutenberg block3 // Gutenberg block 4 4 function diff_check_register_block() { 5 if ( ! function_exists( 'register_block_type' )) {5 if (!function_exists('register_block_type')) { 6 6 return; 7 7 } … … 12 12 wp_register_script( 13 13 $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') 17 17 ); 18 18 wp_register_style( 19 19 $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') 23 23 ); 24 register_block_type( $block_name, array(24 register_block_type($block_name, array( 25 25 'editor_script' => $block_script_handle, 26 26 'editor_style' => $block_style_handle, … … 44 44 ), 45 45 ), 46 ) );46 )); 47 47 } 48 add_action( 'init', 'diff_check_register_block');48 add_action('init', 'diff_check_register_block'); 49 49 50 function diff_check_block_render( $attributes) {50 function diff_check_block_render($attributes) { 51 51 $text1 = $attributes['text1']; 52 52 $text2 = $attributes['text2']; 53 53 54 if ( $attributes['file1'] != '') {55 $text1 = file_get_contents( $attributes['file1']);54 if ($attributes['file1'] != '') { 55 $text1 = file_get_contents($attributes['file1']); 56 56 } 57 57 58 if ( $attributes['file2'] != '') {59 $text2 = file_get_contents( $attributes['file2']);58 if ($attributes['file2'] != '') { 59 $text2 = file_get_contents($attributes['file2']); 60 60 } 61 61 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>'; 64 103 65 104 return '<div class="diff-check">' . $diff . '</div><p>Differences found: ' . $differences_count . '</p>'; -
diff-check/trunk/includes/shortcodes.php
r2878471 r2928790 21 21 } 22 22 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 24 34 $differences_count = substr_count($diff,'<ins>') + substr_count($diff,'<del>'); 25 35
Note: See TracChangeset
for help on using the changeset viewer.