4
4
5
5
class ListDiff extends HtmlDiff
6
6
{
7
+ /** @var array */
7
8
protected $ listWords = array ();
9
+
10
+ /** @var array */
8
11
protected $ listTags = array ();
12
+
13
+ /** @var array */
9
14
protected $ listIsolatedDiffTags = array ();
15
+
16
+ /** @var array */
10
17
protected $ isolatedDiffTags = array (
11
18
'ol ' => '[[REPLACE_ORDERED_LIST]] ' ,
12
19
'ul ' => '[[REPLACE_UNORDERED_LIST]] ' ,
13
20
'dl ' => '[[REPLACE_DEFINITION_LIST]] ' ,
14
21
);
22
+
23
+ /**
24
+ * List (li) placeholder.
25
+ * @var string
26
+ */
15
27
protected static $ listPlaceHolder = "[[REPLACE_LIST_ITEM]] " ;
16
- protected $ listType ; // holds the type of list this is ol, ul, dl
17
- protected $ list ; // hold the old/new content of the content of the list
18
- protected $ childLists ; // contains the old/new child lists content within this list
19
- protected $ textMatches ; // contains the old/new text strings that match
20
- protected $ listsIndex ; // contains the indexed start positions of each list within word string.
28
+
29
+ /**
30
+ * Holds the type of list this is ol, ul, dl.
31
+ * @var string
32
+ */
33
+ protected $ listType ;
34
+
35
+ /**
36
+ * Hold the old/new content of the content of the list.
37
+ * @var array
38
+ */
39
+ protected $ list ;
40
+
41
+ /**
42
+ * Contains the old/new child lists content within this list.
43
+ * @var array
44
+ */
45
+ protected $ childLists ;
46
+
47
+ /**
48
+ * Contains the old/new text strings that match
49
+ * @var array
50
+ */
51
+ protected $ textMatches ;
52
+
53
+ /**
54
+ * Contains the indexed start positions of each list within word string.
55
+ * @var array
56
+ */
57
+ protected $ listsIndex ;
21
58
22
59
/**
23
60
* We're using the same functions as the parent in build() to get us to the point of
@@ -87,6 +124,10 @@ protected function formatThisListContent()
87
124
}
88
125
}
89
126
127
+ /**
128
+ * @param string $tag
129
+ * @return string
130
+ */
90
131
protected function getAndStripTag ($ tag )
91
132
{
92
133
$ content = explode (' ' , preg_replace ("/[^A-Za-z0-9 ]/ " , '' , $ tag ));
@@ -250,6 +291,12 @@ protected function diff()
250
291
$ this ->content .= $ this ->addListTypeWrapper (false );
251
292
}
252
293
294
+ /**
295
+ * Converts the list (li) content arrays to string.
296
+ *
297
+ * @param array $listContentArray
298
+ * @return string
299
+ */
253
300
protected function convertListContentArrayToString ($ listContentArray )
254
301
{
255
302
if (!is_array ($ listContentArray )) {
@@ -278,6 +325,10 @@ protected function convertListContentArrayToString($listContentArray)
278
325
/**
279
326
* Return the contents of each list node.
280
327
* Process any placeholders for nested lists.
328
+ *
329
+ * @param string $text
330
+ * @param array $matches
331
+ * @return string
281
332
*/
282
333
protected function processPlaceholders ($ text , array $ matches )
283
334
{
@@ -313,6 +364,12 @@ protected function processPlaceholders($text, array $matches)
313
364
return implode (' ' , $ returnText );
314
365
}
315
366
367
+ /**
368
+ * Checks to see if a diff tag is in string.
369
+ *
370
+ * @param string $word
371
+ * @return string
372
+ */
316
373
protected function checkWordForDiffTag ($ word )
317
374
{
318
375
foreach ($ this ->isolatedDiffTags as $ diffTag ) {
@@ -334,6 +391,9 @@ protected function checkWordForDiffTag($word)
334
391
335
392
/**
336
393
* Used to remove new lines.
394
+ *
395
+ * @param string $text
396
+ * @return string
337
397
*/
338
398
protected function stripNewLine ($ text )
339
399
{
@@ -342,6 +402,10 @@ protected function stripNewLine($text)
342
402
343
403
/**
344
404
* Grab the list content using the listsIndex array.
405
+ *
406
+ * @param string $indexKey
407
+ * @param array $matches
408
+ * @return array
345
409
*/
346
410
protected function getListContent ($ indexKey = 'new ' , array $ matches )
347
411
{
@@ -360,7 +424,14 @@ protected function getListContent($indexKey = 'new', array $matches)
360
424
return $ bucket ;
361
425
}
362
426
363
- protected function findEndForIndex ($ index , $ start )
427
+ /**
428
+ * Finds the end of list within its index.
429
+ *
430
+ * @param array $index
431
+ * @param integer $start
432
+ * @return integer
433
+ */
434
+ protected function findEndForIndex (array $ index , $ start )
364
435
{
365
436
$ array = array_splice ($ index , $ start );
366
437
$ count = 0 ;
@@ -410,6 +481,9 @@ protected function indexLists()
410
481
411
482
/**
412
483
* Adds the opening or closing list html element, based on listType.
484
+ *
485
+ * @param boolean $opening
486
+ * @return string
413
487
*/
414
488
protected function addListTypeWrapper ($ opening = true )
415
489
{
@@ -427,6 +501,10 @@ public function replaceListIsolatedDiffTags()
427
501
428
502
/**
429
503
* Grab the contents of a list node.
504
+ *
505
+ * @param array $contentArray
506
+ * @param boolean $stripTags
507
+ * @return array
430
508
*/
431
509
protected function getListsContent (array $ contentArray , $ stripTags = true )
432
510
{
@@ -458,7 +536,19 @@ protected function getListsContent(array $contentArray, $stripTags = true)
458
536
return $ lematches ;
459
537
}
460
538
461
- protected function addStringToArrayByDepth ($ word , &$ array , $ targetDepth , $ thisDepth , $ nestedCount )
539
+ /**
540
+ * This function helps build the list content array of a list.
541
+ * If a list has another list within it, the inner list is replaced with the list placeholder and the inner list
542
+ * content becomes a child of the parent list.
543
+ * This goes recursively down.
544
+ *
545
+ * @param string $word
546
+ * @param array $array
547
+ * @param integer $targetDepth
548
+ * @param integer $thisDepth
549
+ * @param array $nestedCount
550
+ */
551
+ protected function addStringToArrayByDepth ($ word , array &$ array , $ targetDepth , $ thisDepth , array $ nestedCount )
462
552
{
463
553
// determine what depth we're at
464
554
if ($ targetDepth == $ thisDepth ) {
@@ -500,6 +590,7 @@ protected function addStringToArrayByDepth($word, &$array, $targetDepth, $thisDe
500
590
);
501
591
502
592
} else {
593
+
503
594
if ($ nestedCount [$ targetDepth ] > count ($ array [count ($ array ) - 1 ]['kids ' ])) {
504
595
$ array [count ($ array ) - 1 ]['kids ' ][] = $ newArray ;
505
596
$ array [count ($ array ) - 1 ]['content ' ] .= self ::$ listPlaceHolder ;
@@ -520,6 +611,12 @@ protected function addStringToArrayByDepth($word, &$array, $targetDepth, $thisDe
520
611
}
521
612
}
522
613
614
+ /**
615
+ * Checks if text is opening list tag.
616
+ *
617
+ * @param string $item
618
+ * @return boolean
619
+ */
523
620
protected function isOpeningListTag ($ item )
524
621
{
525
622
if (preg_match ("#<li[^>]*> \\s*#iU " , $ item )) {
@@ -528,7 +625,13 @@ protected function isOpeningListTag($item)
528
625
529
626
return false ;
530
627
}
531
-
628
+
629
+ /**
630
+ * Check if text is closing list tag.
631
+ *
632
+ * @param string $item
633
+ * @return boolean
634
+ */
532
635
protected function isClosingListTag ($ item )
533
636
{
534
637
if (preg_match ("#</li[^>]*> \\s*#iU " , $ item )) {
0 commit comments