@@ -8,19 +8,19 @@ class HtmlDiff
8
8
public static $ defaultSpecialCaseChars = array ('. ' , ', ' , '( ' , ') ' , '\'' );
9
9
public static $ defaultGroupDiffs = true ;
10
10
11
- private $ content ;
12
- private $ oldText ;
13
- private $ newText ;
14
- private $ oldWords = array ();
15
- private $ newWords = array ();
16
- private $ wordIndices ;
17
- private $ encoding ;
18
- private $ specialCaseOpeningTags = array ();
19
- private $ specialCaseClosingTags = array ();
20
- private $ specialCaseTags ;
21
- private $ specialCaseChars ;
22
- private $ groupDiffs ;
23
- private $ insertSpaceInReplace = false ;
11
+ protected $ content ;
12
+ protected $ oldText ;
13
+ protected $ newText ;
14
+ protected $ oldWords = array ();
15
+ protected $ newWords = array ();
16
+ protected $ wordIndices ;
17
+ protected $ encoding ;
18
+ protected $ specialCaseOpeningTags = array ();
19
+ protected $ specialCaseClosingTags = array ();
20
+ protected $ specialCaseTags ;
21
+ protected $ specialCaseChars ;
22
+ protected $ groupDiffs ;
23
+ protected $ insertSpaceInReplace = false ;
24
24
25
25
public function __construct ($ oldText , $ newText , $ encoding = 'UTF-8 ' , $ specialCaseTags = null , $ groupDiffs = null )
26
26
{
@@ -158,17 +158,17 @@ public function isGroupDiffs()
158
158
return $ this ->groupDiffs ;
159
159
}
160
160
161
- private function getOpeningTag ($ tag )
161
+ protected function getOpeningTag ($ tag )
162
162
{
163
163
return "/< " .$ tag ."[^>]*/i " ;
164
164
}
165
165
166
- private function getClosingTag ($ tag )
166
+ protected function getClosingTag ($ tag )
167
167
{
168
168
return "</ " .$ tag ."> " ;
169
169
}
170
170
171
- private function getStringBetween ($ str , $ start , $ end )
171
+ protected function getStringBetween ($ str , $ start , $ end )
172
172
{
173
173
$ expStr = explode ( $ start , $ str , 2 );
174
174
if ( count ( $ expStr ) > 1 ) {
@@ -183,7 +183,7 @@ private function getStringBetween($str, $start, $end)
183
183
return '' ;
184
184
}
185
185
186
- private function purifyHtml ($ html , $ tags = null )
186
+ protected function purifyHtml ($ html , $ tags = null )
187
187
{
188
188
if ( class_exists ( 'Tidy ' ) && false ) {
189
189
$ config = array ( 'output-xhtml ' => true , 'indent ' => false );
@@ -209,7 +209,7 @@ public function build()
209
209
return $ this ->content ;
210
210
}
211
211
212
- private function indexNewWords ()
212
+ protected function indexNewWords ()
213
213
{
214
214
$ this ->wordIndices = array ();
215
215
foreach ($ this ->newWords as $ i => $ word ) {
@@ -224,18 +224,18 @@ private function indexNewWords()
224
224
}
225
225
}
226
226
227
- private function splitInputsToWords ()
227
+ protected function splitInputsToWords ()
228
228
{
229
229
$ this ->oldWords = $ this ->convertHtmlToListOfWords ( $ this ->explode ( $ this ->oldText ) );
230
230
$ this ->newWords = $ this ->convertHtmlToListOfWords ( $ this ->explode ( $ this ->newText ) );
231
231
}
232
232
233
- private function isPartOfWord ($ text )
233
+ protected function isPartOfWord ($ text )
234
234
{
235
235
return ctype_alnum (str_replace ($ this ->specialCaseChars , '' , $ text ));
236
236
}
237
237
238
- private function convertHtmlToListOfWords ($ characterString )
238
+ protected function convertHtmlToListOfWords ($ characterString )
239
239
{
240
240
$ mode = 'character ' ;
241
241
$ current_word = '' ;
@@ -310,28 +310,28 @@ private function convertHtmlToListOfWords($characterString)
310
310
return $ words ;
311
311
}
312
312
313
- private function isStartOfTag ($ val )
313
+ protected function isStartOfTag ($ val )
314
314
{
315
315
return $ val == "< " ;
316
316
}
317
317
318
- private function isEndOfTag ($ val )
318
+ protected function isEndOfTag ($ val )
319
319
{
320
320
return $ val == "> " ;
321
321
}
322
322
323
- private function isWhiteSpace ($ value )
323
+ protected function isWhiteSpace ($ value )
324
324
{
325
325
return !preg_match ( '[^\s] ' , $ value );
326
326
}
327
327
328
- private function explode ($ value )
328
+ protected function explode ($ value )
329
329
{
330
330
// as suggested by @onassar
331
331
return preg_split ( '//u ' , $ value );
332
332
}
333
333
334
- private function performOperation ($ operation )
334
+ protected function performOperation ($ operation )
335
335
{
336
336
switch ($ operation ->action ) {
337
337
case 'equal ' :
@@ -351,7 +351,7 @@ private function performOperation($operation)
351
351
}
352
352
}
353
353
354
- private function processReplaceOperation ($ operation )
354
+ protected function processReplaceOperation ($ operation )
355
355
{
356
356
$ processDelete = strlen ($ this ->oldText ) > 0 ;
357
357
$ processInsert = strlen ($ this ->newText ) > 0 ;
@@ -369,7 +369,7 @@ private function processReplaceOperation($operation)
369
369
}
370
370
}
371
371
372
- private function processInsertOperation ($ operation , $ cssClass )
372
+ protected function processInsertOperation ($ operation , $ cssClass )
373
373
{
374
374
$ text = array ();
375
375
foreach ($ this ->newWords as $ pos => $ s ) {
@@ -380,7 +380,7 @@ private function processInsertOperation($operation, $cssClass)
380
380
$ this ->insertTag ( "ins " , $ cssClass , $ text );
381
381
}
382
382
383
- private function processDeleteOperation ($ operation , $ cssClass )
383
+ protected function processDeleteOperation ($ operation , $ cssClass )
384
384
{
385
385
$ text = array ();
386
386
foreach ($ this ->oldWords as $ pos => $ s ) {
@@ -391,7 +391,7 @@ private function processDeleteOperation($operation, $cssClass)
391
391
$ this ->insertTag ( "del " , $ cssClass , $ text );
392
392
}
393
393
394
- private function processEqualOperation ($ operation )
394
+ protected function processEqualOperation ($ operation )
395
395
{
396
396
$ result = array ();
397
397
foreach ($ this ->newWords as $ pos => $ s ) {
@@ -402,7 +402,7 @@ private function processEqualOperation($operation)
402
402
$ this ->content .= implode ( "" , $ result );
403
403
}
404
404
405
- private function insertTag ($ tag , $ cssClass , &$ words )
405
+ protected function insertTag ($ tag , $ cssClass , &$ words )
406
406
{
407
407
while (true ) {
408
408
if ( count ( $ words ) == 0 ) {
@@ -458,17 +458,17 @@ private function insertTag($tag, $cssClass, &$words)
458
458
}
459
459
}
460
460
461
- private function checkCondition ($ word , $ condition )
461
+ protected function checkCondition ($ word , $ condition )
462
462
{
463
463
return $ condition == 'tag ' ? $ this ->isTag ( $ word ) : !$ this ->isTag ( $ word );
464
464
}
465
465
466
- private function wrapText ($ text , $ tagName , $ cssClass )
466
+ protected function wrapText ($ text , $ tagName , $ cssClass )
467
467
{
468
468
return sprintf ( '<%1$s class="%2$s">%3$s</%1$s> ' , $ tagName , $ cssClass , $ text );
469
469
}
470
470
471
- private function extractConsecutiveWords (&$ words , $ condition )
471
+ protected function extractConsecutiveWords (&$ words , $ condition )
472
472
{
473
473
$ indexOfFirstTag = null ;
474
474
foreach ($ words as $ i => $ word ) {
@@ -502,22 +502,22 @@ private function extractConsecutiveWords(&$words, $condition)
502
502
}
503
503
}
504
504
505
- private function isTag ($ item )
505
+ protected function isTag ($ item )
506
506
{
507
507
return $ this ->isOpeningTag ( $ item ) || $ this ->isClosingTag ( $ item );
508
508
}
509
509
510
- private function isOpeningTag ($ item )
510
+ protected function isOpeningTag ($ item )
511
511
{
512
512
return preg_match ( "#<[^>]+> \\s*#iU " , $ item );
513
513
}
514
514
515
- private function isClosingTag ($ item )
515
+ protected function isClosingTag ($ item )
516
516
{
517
517
return preg_match ( "#</[^>]+> \\s*#iU " , $ item );
518
518
}
519
519
520
- private function operations ()
520
+ protected function operations ()
521
521
{
522
522
$ positionInOld = 0 ;
523
523
$ positionInNew = 0 ;
@@ -551,15 +551,15 @@ private function operations()
551
551
return $ operations ;
552
552
}
553
553
554
- private function matchingBlocks ()
554
+ protected function matchingBlocks ()
555
555
{
556
556
$ matchingBlocks = array ();
557
557
$ this ->findMatchingBlocks ( 0 , count ( $ this ->oldWords ), 0 , count ( $ this ->newWords ), $ matchingBlocks );
558
558
559
559
return $ matchingBlocks ;
560
560
}
561
561
562
- private function findMatchingBlocks ($ startInOld , $ endInOld , $ startInNew , $ endInNew , &$ matchingBlocks )
562
+ protected function findMatchingBlocks ($ startInOld , $ endInOld , $ startInNew , $ endInNew , &$ matchingBlocks )
563
563
{
564
564
$ match = $ this ->findMatch ( $ startInOld , $ endInOld , $ startInNew , $ endInNew );
565
565
if ($ match !== null ) {
@@ -573,14 +573,14 @@ private function findMatchingBlocks($startInOld, $endInOld, $startInNew, $endInN
573
573
}
574
574
}
575
575
576
- private function stripTagAttributes ($ word )
576
+ protected function stripTagAttributes ($ word )
577
577
{
578
578
$ word = explode ( ' ' , trim ( $ word , '<> ' ) );
579
579
580
580
return '< ' . $ word [ 0 ] . '> ' ;
581
581
}
582
582
583
- private function findMatch ($ startInOld , $ endInOld , $ startInNew , $ endInNew )
583
+ protected function findMatch ($ startInOld , $ endInOld , $ startInNew , $ endInNew )
584
584
{
585
585
$ bestMatchInOld = $ startInOld ;
586
586
$ bestMatchInNew = $ startInNew ;
0 commit comments