@@ -42,68 +42,8 @@ function base_dir()
4242$ module = Module::find ($ id_module );
4343
4444// Aggiunta della classe per il modulo
45- echo '<div class="module-aggiornamenti">
46-
47- <style>
48- .query-preview,
49- .query-full {
50- font-size: 11px;
51- line-height: 1.3;
52- background-color: #f8f9fa;
53- border: 1px solid #e9ecef;
54- border-radius: 3px;
55- padding: 8px;
56- display: block;
57- white-space: pre-wrap;
58- word-break: break-all;
59- }
60-
61- .btn-xs {
62- padding: 4px 8px;
63- font-size: 11px;
64- line-height: 1.3;
65- border-radius: 3px;
66- font-weight: 600;
67- border: 1px solid #007bff;
68- color: #007bff;
69- background-color: white;
70- transition: all 0.2s ease;
71- }
72-
73- .btn-xs i {
74- font-size: 10px;
75- margin-right: 3px;
76- }
77-
78- .btn-xs:hover {
79- background-color: #007bff;
80- color: white;
81- border-color: #007bff;
82- transform: translateY(-1px);
83- box-shadow: 0 2px 4px rgba(0,123,255,0.2);
84- }
85-
86- /* Padding per le celle della tabella */
87- .table td {
88- padding: 12px 8px !important;
89- vertical-align: top;
90- }
91-
92- .table th {
93- padding: 10px 8px !important;
94- }
95- </style> ' ;
45+ echo '<div class="module-aggiornamenti"> ' ;
9646
97- if (!function_exists ('normalizeForDiff ' )) {
98- function normalizeForDiff ($ text )
99- {
100- $ text = preg_replace ('/<br\s*\/?>/i ' , '' , (string ) $ text );
101- $ text = preg_replace ('/\s+/ ' , ' ' , (string ) $ text );
102- $ text = str_replace (['" ' , "' " ], "' " , $ text );
103- $ text = html_entity_decode ($ text , ENT_QUOTES | ENT_HTML5 , 'UTF-8 ' );
104- return trim ($ text );
105- }
106- }
10747
10848function createCollapsibleQuery ($ query_content , $ row_id , $ column_type ) {
10949 if (empty ($ query_content ) || $ query_content === '<span class="text-muted">-</span> ' ) {
@@ -153,8 +93,8 @@ function highlightDifferences($current, $expected) {
15393 ];
15494 }
15595
156- $ current_normalized = normalizeForDiff ($ current );
157- $ expected_normalized = normalizeForDiff ($ expected );
96+ $ current_normalized = normalizeModuleOptions ($ current );
97+ $ expected_normalized = normalizeModuleOptions ($ expected );
15898
15999 $ current_words = preg_split ('/(\s+|[(), \'"`]|<[^>]*>)/ ' , $ current_normalized , -1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
160100 $ expected_words = preg_split ('/(\s+|[(), \'"`]|<[^>]*>)/ ' , $ expected_normalized , -1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
@@ -169,22 +109,39 @@ function highlightDifferences($current, $expected) {
169109 $ current_highlighted = '' ;
170110 $ expected_highlighted = '' ;
171111
172- $ i = 0 ; $ j = 0 ;
173- while ($ i < count ($ current_words ) || $ j < count ($ expected_words )) {
174- if ($ i < count ($ current_words ) && $ j < count ($ expected_words ) && $ current_words [$ i ] === $ expected_words [$ j ]) {
112+ $ current_count = count ($ current_words );
113+ $ expected_count = count ($ expected_words );
114+
115+ $ lcs = array_fill (0 , $ current_count + 1 , array_fill (0 , $ expected_count + 1 , 0 ));
116+
117+ for ($ i = $ current_count - 1 ; $ i >= 0 ; --$ i ) {
118+ for ($ j = $ expected_count - 1 ; $ j >= 0 ; --$ j ) {
119+ if ($ current_words [$ i ] === $ expected_words [$ j ]) {
120+ $ lcs [$ i ][$ j ] = $ lcs [$ i + 1 ][$ j + 1 ] + 1 ;
121+ } else {
122+ $ lcs [$ i ][$ j ] = max ($ lcs [$ i + 1 ][$ j ], $ lcs [$ i ][$ j + 1 ]);
123+ }
124+ }
125+ }
126+
127+ $ i = 0 ;
128+ $ j = 0 ;
129+ while ($ i < $ current_count || $ j < $ expected_count ) {
130+ if ($ i < $ current_count && $ j < $ expected_count && $ current_words [$ i ] === $ expected_words [$ j ]) {
175131 // Parti uguali: mostra senza evidenziazione
176132 $ word = htmlspecialchars ($ current_words [$ i ]);
177133 $ current_highlighted .= $ word ;
178134 $ expected_highlighted .= $ word ;
179- $ i ++; $ j ++;
180- } elseif ($ i < count ($ current_words ) && ($ j >= count ($ expected_words ) || $ current_words [$ i ] !== $ expected_words [$ j ])) {
181- // Parti aggiunte nel current: evidenzia in verde
182- $ current_highlighted .= '<span class="diff-added" style="background-color: #d4edda; color: #155724;"> ' . htmlspecialchars ($ current_words [$ i ]) . '</span> ' ;
183- $ i ++;
184- } elseif ($ j < count ($ expected_words )) {
185- // Parti rimosse (presenti nell'expected ma non nel current): evidenzia in rosso
186- $ expected_highlighted .= '<span class="diff-removed" style="background-color: #f8d7da; color: #721c24;"> ' . htmlspecialchars ($ expected_words [$ j ]) . '</span> ' ;
187- $ j ++;
135+ ++$ i ;
136+ ++$ j ;
137+ } elseif ($ i < $ current_count && ($ j >= $ expected_count || $ lcs [$ i + 1 ][$ j ] >= $ lcs [$ i ][$ j + 1 ])) {
138+ $ current_highlighted .= '<span class="diff-removed"> ' .htmlspecialchars ($ current_words [$ i ]).'</span> ' ;
139+ ++$ i ;
140+ } elseif ($ j < $ expected_count ) {
141+ $ expected_highlighted .= '<span class="diff-added"> ' .htmlspecialchars ($ expected_words [$ j ]).'</span> ' ;
142+ ++$ j ;
143+ } else {
144+ break ;
188145 }
189146 }
190147
0 commit comments