PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.01
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
← All changes | app/Services/Parsedown.php +75 -78 2.7.0 → 2.10.01 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +// phpcs:disable -- Third-party library (Parsedown by Emanuil Rusev). Not subject to project coding standards.
2 3
3 4 namespace FluentCommunity\App\Services;
4 5 #
5 6 #
@@ -57,31 +58,31 @@
57 58 # Lines
58 59 #
59 60
60 61 protected $BlockTypes = array(
61 - '#' => array('Header'),
62 - '*' => array('Rule', 'List'),
63 - '+' => array('List'),
64 - '-' => array('SetextHeader', 'Table', 'Rule', 'List'),
65 - '0' => array('List'),
66 - '1' => array('List'),
67 - '2' => array('List'),
68 - '3' => array('List'),
69 - '4' => array('List'),
70 - '5' => array('List'),
71 - '6' => array('List'),
72 - '7' => array('List'),
73 - '8' => array('List'),
74 - '9' => array('List'),
75 - ':' => array('Table'),
76 - '<' => array('Comment', 'Markup'),
77 - '=' => array('SetextHeader'),
78 - '>' => array('Quote'),
79 - '[' => array('Reference'),
80 - '_' => array('Rule'),
81 - '`' => array('FencedCode'),
82 - '|' => array('Table'),
83 - '~' => array('FencedCode'),
62 + '#' => array( 'Header' ),
63 + '*' => array( 'Rule', 'List' ),
64 + '+' => array( 'List' ),
65 + '-' => array( 'SetextHeader', 'Table', 'Rule', 'List' ),
66 + '0' => array( 'List' ),
67 + '1' => array( 'List' ),
68 + '2' => array( 'List' ),
69 + '3' => array( 'List' ),
70 + '4' => array( 'List' ),
71 + '5' => array( 'List' ),
72 + '6' => array( 'List' ),
73 + '7' => array( 'List' ),
74 + '8' => array( 'List' ),
75 + '9' => array( 'List' ),
76 + ':' => array( 'Table' ),
77 + '<' => array( 'Comment', 'Markup' ),
78 + '=' => array( 'SetextHeader' ),
79 + '>' => array( 'Quote' ),
80 + '[' => array( 'Reference' ),
81 + '_' => array( 'Rule' ),
82 + '`' => array( 'FencedCode' ),
83 + '|' => array( 'Table' ),
84 + '~' => array( 'FencedCode' ),
84 85 );
85 86
86 87 # ~
87 88
@@ -94,9 +95,9 @@
94 95 public function __construct($config = [])
95 96 {
96 97
97 98 $config = wp_parse_args($config, [
98 - 'minHeaderLevel' => 0
99 + 'minHeaderLevel' => 0,
99 100 ]);
100 101
101 102 $this->minHeaderLevel = $config['minHeaderLevel'];
102 103 }
@@ -121,9 +122,9 @@
121 122 # make sure no definitions are set
122 123 $this->DefinitionData = array();
123 124
124 125 # standardize line breaks
125 - $text = str_replace(array("\r\n", "\r"), "\n", $text);
126 + $text = str_replace(array( "\r\n", "\r" ), "\n", $text);
126 127
127 128 # remove surrounding line breaks
128 129 $text = trim($text, "\n");
129 130
@@ -212,9 +213,9 @@
212 213 $text = $indent > 0 ? substr($line, $indent) : $line;
213 214
214 215 # ~
215 216
216 - $Line = array('body' => $line, 'indent' => $indent, 'text' => $text);
217 + $Line = array( 'body' => $line, 'indent' => $indent, 'text' => $text );
217 218
218 219 # ~
219 220
220 221 if (isset($CurrentBlock['continuable'])) {
@@ -224,13 +225,11 @@
224 225 if (isset($Block)) {
225 226 $CurrentBlock = $Block;
226 227
227 228 continue;
228 - } else {
229 - if ($this->isBlockCompletable($CurrentBlock['type'])) {
229 + } elseif ($this->isBlockCompletable($CurrentBlock['type'])) {
230 230 $methodName = 'block' . $CurrentBlock['type'] . 'Complete';
231 231 $CurrentBlock = $this->$methodName($CurrentBlock);
232 - }
233 232 }
234 233 }
235 234
236 235 # ~
@@ -314,9 +313,9 @@
314 313 protected function extractElement(array $Component)
315 314 {
316 315 if (!isset($Component['element'])) {
317 316 if (isset($Component['markup'])) {
318 - $Component['element'] = array('rawHtml' => $Component['markup']);
317 + $Component['element'] = array( 'rawHtml' => $Component['markup'] );
319 318 } elseif (isset($Component['hidden'])) {
320 319 $Component['element'] = array();
321 320 }
322 321 }
@@ -462,9 +461,9 @@
462 461 * U+000D CARRIAGE RETURN (CR).
463 462 */
464 463 $language = substr($infostring, 0, strcspn($infostring, " \t\n\f\r"));
465 464
466 - $Element['attributes'] = array('class' => "language-$language");
465 + $Element['attributes'] = array( 'class' => "language-$language" );
467 466 }
468 467
469 468 $Block = array(
470 469 'char' => $marker,
@@ -544,9 +543,9 @@
544 543 'handler' => array(
545 544 'function' => 'lineElements',
546 545 'argument' => $text,
547 546 'destination' => 'elements',
548 - )
547 + ),
549 548 ),
550 549 );
551 550
552 551 return $Block;
@@ -554,11 +553,11 @@
554 553
555 554 #
556 555 # List
557 556
558 - protected function blockList($Line, array $CurrentBlock = null)
557 + protected function blockList($Line, ?array $CurrentBlock = null)
559 558 {
560 - list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]{1,9}+[.\)]');
559 + list($name, $pattern) = $Line['text'][0] <= '-' ? array( 'ul', '[*+-]' ) : array( 'ol', '[0-9]{1,9}+[.\)]' );
561 560
562 561 if (preg_match('/^(' . $pattern . '([ ]++|$))(.*+)/', $Line['text'], $matches)) {
563 562 $contentIndent = strlen($matches[2]);
564 563
@@ -598,9 +597,9 @@
598 597 ) {
599 598 return;
600 599 }
601 600
602 - $Block['element']['attributes'] = array('start' => $listStart);
601 + $Block['element']['attributes'] = array( 'start' => $listStart );
603 602 }
604 603 }
605 604
606 605 $Block['li'] = array(
@@ -606,11 +605,11 @@
606 605 $Block['li'] = array(
607 606 'name' => 'li',
608 607 'handler' => array(
609 608 'function' => 'li',
610 - 'argument' => !empty($matches[3]) ? array($matches[3]) : array(),
611 - 'destination' => 'elements'
612 - )
609 + 'argument' => !empty($matches[3]) ? array( $matches[3] ) : array(),
610 + 'destination' => 'elements',
611 + ),
613 612 );
614 613
615 614 $Block['element']['elements'] [] = &$Block['li'];
616 615
@@ -654,11 +653,11 @@
654 653 $Block['li'] = array(
655 654 'name' => 'li',
656 655 'handler' => array(
657 656 'function' => 'li',
658 - 'argument' => array($text),
659 - 'destination' => 'elements'
660 - )
657 + 'argument' => array( $text ),
658 + 'destination' => 'elements',
659 + ),
661 660 );
662 661
663 662 $Block['element']['elements'] [] = &$Block['li'];
664 663
@@ -721,9 +720,9 @@
721 720 'handler' => array(
722 721 'function' => 'linesElements',
723 722 'argument' => (array)$matches[1],
724 723 'destination' => 'elements',
725 - )
724 + ),
726 725 ),
727 726 );
728 727
729 728 return $Block;
@@ -769,9 +768,9 @@
769 768
770 769 #
771 770 # Setext
772 771
773 - protected function blockSetextHeader($Line, array $Block = null)
772 + protected function blockSetextHeader($Line, ?array $Block = null)
774 773 {
775 774 if (!isset($Block) or $Block['type'] !== 'Paragraph' or isset($Block['interrupted'])) {
776 775 return;
777 776 }
@@ -849,9 +848,9 @@
849 848
850 849 #
851 850 # Table
852 851
853 - protected function blockTable($Line, array $Block = null)
852 + protected function blockTable($Line, ?array $Block = null)
854 853 {
855 854 if (!isset($Block) or $Block['type'] !== 'Paragraph' or isset($Block['interrupted'])) {
856 855 return;
857 856 }
@@ -921,9 +920,9 @@
921 920 'handler' => array(
922 921 'function' => 'lineElements',
923 922 'argument' => $headerCell,
924 923 'destination' => 'elements',
925 - )
924 + ),
926 925 );
927 926
928 927 if (isset($alignments[$index])) {
929 928 $alignment = $alignments[$index];
@@ -990,9 +989,9 @@
990 989 'handler' => array(
991 990 'function' => 'lineElements',
992 991 'argument' => $cell,
993 992 'destination' => 'elements',
994 - )
993 + ),
995 994 );
996 995
997 996 if (isset($Block['alignments'][$index])) {
998 997 $Element['attributes'] = array(
@@ -1048,18 +1047,18 @@
1048 1047 # Inline Elements
1049 1048 #
1050 1049
1051 1050 protected $InlineTypes = array(
1052 - '!' => array('Image'),
1053 - '&' => array('SpecialCharacter'),
1054 - '*' => array('Emphasis'),
1055 - ':' => array('Url'),
1056 - '<' => array('UrlTag', 'EmailTag', 'Markup'),
1057 - '[' => array('Link'),
1058 - '_' => array('Emphasis'),
1059 - '`' => array('Code'),
1060 - '~' => array('Strikethrough'),
1061 - '\\' => array('EscapeSequence'),
1051 + '!' => array( 'Image' ),
1052 + '&' => array( 'SpecialCharacter' ),
1053 + '*' => array( 'Emphasis' ),
1054 + ':' => array( 'Url' ),
1055 + '<' => array( 'UrlTag', 'EmailTag', 'Markup' ),
1056 + '[' => array( 'Link' ),
1057 + '_' => array( 'Emphasis' ),
1058 + '`' => array( 'Code' ),
1059 + '~' => array( 'Strikethrough' ),
1060 + '\\' => array( 'EscapeSequence' ),
1062 1061 );
1063 1062
1064 1063 # ~
1065 1064
@@ -1076,9 +1075,9 @@
1076 1075
1077 1076 protected function lineElements($text, $nonNestables = array())
1078 1077 {
1079 1078 # standardize line breaks
1080 - $text = str_replace(array("\r\n", "\r"), "\n", $text);
1079 + $text = str_replace(array( "\r\n", "\r" ), "\n", $text);
1081 1080
1082 1081 $Elements = array();
1083 1082
1084 1083 $nonNestables = (empty($nonNestables)
@@ -1092,9 +1091,9 @@
1092 1091 $marker = $excerpt[0];
1093 1092
1094 1093 $markerPosition = strlen($text) - strlen($excerpt);
1095 1094
1096 - $Excerpt = array('text' => $excerpt, 'context' => $text);
1095 + $Excerpt = array( 'text' => $excerpt, 'context' => $text );
1097 1096
1098 1097 foreach ($this->InlineTypes[$marker] as $inlineType) {
1099 1098 # check to see if the current inline type is nestable in the current context
1100 1099
@@ -1178,10 +1177,10 @@
1178 1177
1179 1178 $Inline['element']['elements'] = self::pregReplaceElements(
1180 1179 $this->breaksEnabled ? '/[ ]*+\n/' : '/(?:[ ]*+\\\\|[ ]{2,}+)\n/',
1181 1180 array(
1182 - array('name' => 'br'),
1183 - array('text' => "\n"),
1181 + array( 'name' => 'br' ),
1182 + array( 'text' => "\n" ),
1184 1183 ),
1185 1184 $text
1186 1185 );
1187 1186
@@ -1258,9 +1257,9 @@
1258 1257 'handler' => array(
1259 1258 'function' => 'lineElements',
1260 1259 'argument' => $matches[1],
1261 1260 'destination' => 'elements',
1262 - )
1261 + ),
1263 1262 ),
1264 1263 );
1265 1264 }
1266 1265
@@ -1267,9 +1266,9 @@
1267 1266 protected function inlineEscapeSequence($Excerpt)
1268 1267 {
1269 1268 if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters)) {
1270 1269 return array(
1271 - 'element' => array('rawHtml' => $Excerpt['text'][1]),
1270 + 'element' => array( 'rawHtml' => $Excerpt['text'][1] ),
1272 1271 'extent' => 2,
1273 1272 );
1274 1273 }
1275 1274 }
@@ -1315,9 +1314,9 @@
1315 1314 'function' => 'lineElements',
1316 1315 'argument' => null,
1317 1316 'destination' => 'elements',
1318 1317 ),
1319 - 'nonNestables' => array('Url', 'Link'),
1318 + 'nonNestables' => array( 'Url', 'Link' ),
1320 1319 'attributes' => array(
1321 1320 'href' => null,
1322 1321 'title' => null,
1323 1322 ),
@@ -1378,9 +1377,9 @@
1378 1377 }
1379 1378
1380 1379 if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt['text'], $matches)) {
1381 1380 return array(
1382 - 'element' => array('rawHtml' => $matches[0]),
1381 + 'element' => array( 'rawHtml' => $matches[0] ),
1383 1382 'extent' => strlen($matches[0]),
1384 1383 );
1385 1384 }
1386 1385
@@ -1385,9 +1384,9 @@
1385 1384 }
1386 1385
1387 1386 if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?+[^-])*-->/s', $Excerpt['text'], $matches)) {
1388 1387 return array(
1389 - 'element' => array('rawHtml' => $matches[0]),
1388 + 'element' => array( 'rawHtml' => $matches[0] ),
1390 1389 'extent' => strlen($matches[0]),
1391 1390 );
1392 1391 }
1393 1392
@@ -1392,9 +1391,9 @@
1392 1391 }
1393 1392
1394 1393 if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w[\w-]*+(?:[ ]*+' . $this->regexHtmlAttribute . ')*+[ ]*+\/?>/s', $Excerpt['text'], $matches)) {
1395 1394 return array(
1396 - 'element' => array('rawHtml' => $matches[0]),
1395 + 'element' => array( 'rawHtml' => $matches[0] ),
1397 1396 'extent' => strlen($matches[0]),
1398 1397 );
1399 1398 }
1400 1399 }
@@ -1404,9 +1403,9 @@
1404 1403 if (substr($Excerpt['text'], 1, 1) !== ' ' and strpos($Excerpt['text'], ';') !== false
1405 1404 and preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches)
1406 1405 ) {
1407 1406 return array(
1408 - 'element' => array('rawHtml' => '&' . $matches[1] . ';'),
1407 + 'element' => array( 'rawHtml' => '&' . $matches[1] . ';' ),
1409 1408 'extent' => strlen($matches[0]),
1410 1409 );
1411 1410 }
1412 1411
@@ -1427,9 +1426,9 @@
1427 1426 'handler' => array(
1428 1427 'function' => 'lineElements',
1429 1428 'argument' => $matches[1],
1430 1429 'destination' => 'elements',
1431 - )
1430 + ),
1432 1431 ),
1433 1432 );
1434 1433 }
1435 1434 }
@@ -1522,14 +1521,14 @@
1522 1521 }
1523 1522
1524 1523 protected function handleElementRecursive(array $Element)
1525 1524 {
1526 - return $this->elementApplyRecursive(array($this, 'handle'), $Element);
1525 + return $this->elementApplyRecursive(array( $this, 'handle' ), $Element);
1527 1526 }
1528 1527
1529 1528 protected function handleElementsRecursive(array $Elements)
1530 1529 {
1531 - return $this->elementsApplyRecursive(array($this, 'handle'), $Elements);
1530 + return $this->elementsApplyRecursive(array( $this, 'handle' ), $Elements);
1532 1531 }
1533 1532
1534 1533 protected function elementApplyRecursive($closure, array $Element)
1535 1534 {
@@ -1624,14 +1623,12 @@
1624 1623 if (isset($Element['elements'])) {
1625 1624 $markup .= $this->elements($Element['elements']);
1626 1625 } elseif (isset($Element['element'])) {
1627 1626 $markup .= $this->element($Element['element']);
1627 + } elseif (!$permitRawHtml) {
1628 + $markup .= self::escape($text ?? '', true);
1628 1629 } else {
1629 - if (!$permitRawHtml) {
1630 - $markup .= self::escape($text, true);
1631 - } else {
1632 - $markup .= $text;
1633 - }
1630 + $markup .= $text ?? '';
1634 1631 }
1635 1632
1636 1633 $markup .= $hasName ? '</' . $Element['name'] . '>' : '';
1637 1634 } elseif ($hasName) {
@@ -1699,9 +1696,9 @@
1699 1696 $offset = $matches[0][1];
1700 1697 $before = substr($text, 0, $offset);
1701 1698 $after = substr($text, $offset + strlen($matches[0][0]));
1702 1699
1703 - $newElements[] = array('text' => $before);
1700 + $newElements[] = array( 'text' => $before );
1704 1701
1705 1702 foreach ($Elements as $Element) {
1706 1703 $newElements[] = $Element;
1707 1704 }
@@ -1708,9 +1705,9 @@
1708 1705
1709 1706 $text = $after;
1710 1707 }
1711 1708
1712 - $newElements[] = array('text' => $text);
1709 + $newElements[] = array( 'text' => $text );
1713 1710
1714 1711 return $newElements;
1715 1712 }
1716 1713
@@ -1814,9 +1811,9 @@
1814 1811 #
1815 1812 # Read-Only
1816 1813
1817 1814 protected $specialCharacters = array(
1818 - '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', '~'
1815 + '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', '~',
1819 1816 );
1820 1817
1821 1818 protected $StrongRegex = array(
1822 1819 '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*+[*])+?)[*]{2}(?![*])/s',