@@ -7,9 +7,9 @@ |
||
7 | 7 | * Released under the MIT license. See license.txt for details. |
8 | 8 | */ |
9 | 9 | |
10 | -require dirname(__FILE__) . '/Puc/v4p4/Factory.php'; |
|
11 | -require dirname(__FILE__) . '/Puc/v4/Factory.php'; |
|
12 | -require dirname(__FILE__) . '/Puc/v4p4/Autoloader.php'; |
|
10 | +require dirname(__FILE__).'/Puc/v4p4/Factory.php'; |
|
11 | +require dirname(__FILE__).'/Puc/v4/Factory.php'; |
|
12 | +require dirname(__FILE__).'/Puc/v4p4/Autoloader.php'; |
|
13 | 13 | new Puc_v4p4_Autoloader(); |
14 | 14 | |
15 | 15 | //Register classes defined in this file with the factory. |
@@ -1528,8 +1528,8 @@ |
||
1528 | 1528 | 'q', 'rt', 'ins', 'font', 'strong', |
1529 | 1529 | 's', 'tt', 'sub', 'mark', |
1530 | 1530 | 'u', 'xm', 'sup', 'nobr', |
1531 | - 'var', 'ruby', |
|
1532 | - 'wbr', 'span', |
|
1533 | - 'time', |
|
1531 | + 'var', 'ruby', |
|
1532 | + 'wbr', 'span', |
|
1533 | + 'time', |
|
1534 | 1534 | ); |
1535 | 1535 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | foreach ($parts as $part) |
149 | 149 | { |
150 | - $shortage = 4 - mb_strlen($line, 'utf-8') % 4; |
|
150 | + $shortage = 4 - mb_strlen($line, 'utf-8')%4; |
|
151 | 151 | |
152 | 152 | $line .= str_repeat(' ', $shortage); |
153 | 153 | $line .= $part; |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | while (isset($line[$indent]) and $line[$indent] === ' ') |
160 | 160 | { |
161 | - $indent ++; |
|
161 | + $indent++; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | $text = $indent > 0 ? substr($line, $indent) : $line; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | foreach ($this->BlockTypes[$marker] as $blockType) |
204 | 204 | { |
205 | - $blockTypes []= $blockType; |
|
205 | + $blockTypes [] = $blockType; |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
@@ -217,9 +217,9 @@ discard block |
||
217 | 217 | { |
218 | 218 | $Block['type'] = $blockType; |
219 | 219 | |
220 | - if ( ! isset($Block['identified'])) |
|
220 | + if (!isset($Block['identified'])) |
|
221 | 221 | { |
222 | - $Blocks []= $CurrentBlock; |
|
222 | + $Blocks [] = $CurrentBlock; |
|
223 | 223 | |
224 | 224 | $Block['identified'] = true; |
225 | 225 | } |
@@ -237,13 +237,13 @@ discard block |
||
237 | 237 | |
238 | 238 | # ~ |
239 | 239 | |
240 | - if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) |
|
240 | + if (isset($CurrentBlock) and !isset($CurrentBlock['type']) and !isset($CurrentBlock['interrupted'])) |
|
241 | 241 | { |
242 | 242 | $CurrentBlock['element']['text'] .= "\n".$text; |
243 | 243 | } |
244 | 244 | else |
245 | 245 | { |
246 | - $Blocks []= $CurrentBlock; |
|
246 | + $Blocks [] = $CurrentBlock; |
|
247 | 247 | |
248 | 248 | $CurrentBlock = $this->paragraph($Line); |
249 | 249 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | |
261 | 261 | # ~ |
262 | 262 | |
263 | - $Blocks []= $CurrentBlock; |
|
263 | + $Blocks [] = $CurrentBlock; |
|
264 | 264 | |
265 | 265 | unset($Blocks[0]); |
266 | 266 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | |
292 | 292 | protected function blockCode($Line, $Block = null) |
293 | 293 | { |
294 | - if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted'])) |
|
294 | + if (isset($Block) and !isset($Block['type']) and !isset($Block['interrupted'])) |
|
295 | 295 | { |
296 | 296 | return; |
297 | 297 | } |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | return; |
380 | 380 | } |
381 | 381 | |
382 | - $Block['markup'] .= "\n" . $Line['body']; |
|
382 | + $Block['markup'] .= "\n".$Line['body']; |
|
383 | 383 | |
384 | 384 | if (preg_match('/-->$/', $Line['text'])) |
385 | 385 | { |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | return $Block; |
447 | 447 | } |
448 | 448 | |
449 | - $Block['element']['text']['text'] .= "\n".$Line['body'];; |
|
449 | + $Block['element']['text']['text'] .= "\n".$Line['body']; ; |
|
450 | 450 | |
451 | 451 | return $Block; |
452 | 452 | } |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | |
474 | 474 | while (isset($Line['text'][$level]) and $Line['text'][$level] === '#') |
475 | 475 | { |
476 | - $level ++; |
|
476 | + $level++; |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | if ($level > 6) |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | |
486 | 486 | $Block = array( |
487 | 487 | 'element' => array( |
488 | - 'name' => 'h' . min(6, $level), |
|
488 | + 'name' => 'h'.min(6, $level), |
|
489 | 489 | 'text' => $text, |
490 | 490 | 'handler' => 'line', |
491 | 491 | ), |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | ), |
522 | 522 | ); |
523 | 523 | |
524 | - $Block['element']['text'] []= & $Block['li']; |
|
524 | + $Block['element']['text'] [] = & $Block['li']; |
|
525 | 525 | |
526 | 526 | return $Block; |
527 | 527 | } |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | { |
534 | 534 | if (isset($Block['interrupted'])) |
535 | 535 | { |
536 | - $Block['li']['text'] []= ''; |
|
536 | + $Block['li']['text'] [] = ''; |
|
537 | 537 | |
538 | 538 | unset($Block['interrupted']); |
539 | 539 | } |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | ), |
551 | 551 | ); |
552 | 552 | |
553 | - $Block['element']['text'] []= & $Block['li']; |
|
553 | + $Block['element']['text'] [] = & $Block['li']; |
|
554 | 554 | |
555 | 555 | return $Block; |
556 | 556 | } |
@@ -560,22 +560,22 @@ discard block |
||
560 | 560 | return $Block; |
561 | 561 | } |
562 | 562 | |
563 | - if ( ! isset($Block['interrupted'])) |
|
563 | + if (!isset($Block['interrupted'])) |
|
564 | 564 | { |
565 | 565 | $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); |
566 | 566 | |
567 | - $Block['li']['text'] []= $text; |
|
567 | + $Block['li']['text'] [] = $text; |
|
568 | 568 | |
569 | 569 | return $Block; |
570 | 570 | } |
571 | 571 | |
572 | 572 | if ($Line['indent'] > 0) |
573 | 573 | { |
574 | - $Block['li']['text'] []= ''; |
|
574 | + $Block['li']['text'] [] = ''; |
|
575 | 575 | |
576 | 576 | $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); |
577 | 577 | |
578 | - $Block['li']['text'] []= $text; |
|
578 | + $Block['li']['text'] [] = $text; |
|
579 | 579 | |
580 | 580 | unset($Block['interrupted']); |
581 | 581 | |
@@ -608,19 +608,19 @@ discard block |
||
608 | 608 | { |
609 | 609 | if (isset($Block['interrupted'])) |
610 | 610 | { |
611 | - $Block['element']['text'] []= ''; |
|
611 | + $Block['element']['text'] [] = ''; |
|
612 | 612 | |
613 | 613 | unset($Block['interrupted']); |
614 | 614 | } |
615 | 615 | |
616 | - $Block['element']['text'] []= $matches[1]; |
|
616 | + $Block['element']['text'] [] = $matches[1]; |
|
617 | 617 | |
618 | 618 | return $Block; |
619 | 619 | } |
620 | 620 | |
621 | - if ( ! isset($Block['interrupted'])) |
|
621 | + if (!isset($Block['interrupted'])) |
|
622 | 622 | { |
623 | - $Block['element']['text'] []= $Line['text']; |
|
623 | + $Block['element']['text'] [] = $Line['text']; |
|
624 | 624 | |
625 | 625 | return $Block; |
626 | 626 | } |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | |
649 | 649 | protected function blockSetextHeader($Line, array $Block = null) |
650 | 650 | { |
651 | - if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
651 | + if (!isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
652 | 652 | { |
653 | 653 | return; |
654 | 654 | } |
@@ -723,14 +723,14 @@ discard block |
||
723 | 723 | |
724 | 724 | if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open |
725 | 725 | { |
726 | - $Block['depth'] ++; |
|
726 | + $Block['depth']++; |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close |
730 | 730 | { |
731 | 731 | if ($Block['depth'] > 0) |
732 | 732 | { |
733 | - $Block['depth'] --; |
|
733 | + $Block['depth']--; |
|
734 | 734 | } |
735 | 735 | else |
736 | 736 | { |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | |
787 | 787 | protected function blockTable($Line, array $Block = null) |
788 | 788 | { |
789 | - if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
789 | + if (!isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
790 | 790 | { |
791 | 791 | return; |
792 | 792 | } |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | $alignment = $alignment === 'left' ? 'center' : 'right'; |
824 | 824 | } |
825 | 825 | |
826 | - $alignments []= $alignment; |
|
826 | + $alignments [] = $alignment; |
|
827 | 827 | } |
828 | 828 | |
829 | 829 | # ~ |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | ); |
857 | 857 | } |
858 | 858 | |
859 | - $HeaderElements []= $HeaderElement; |
|
859 | + $HeaderElements [] = $HeaderElement; |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | # ~ |
@@ -870,18 +870,18 @@ discard block |
||
870 | 870 | ), |
871 | 871 | ); |
872 | 872 | |
873 | - $Block['element']['text'] []= array( |
|
873 | + $Block['element']['text'] [] = array( |
|
874 | 874 | 'name' => 'thead', |
875 | 875 | 'handler' => 'elements', |
876 | 876 | ); |
877 | 877 | |
878 | - $Block['element']['text'] []= array( |
|
878 | + $Block['element']['text'] [] = array( |
|
879 | 879 | 'name' => 'tbody', |
880 | 880 | 'handler' => 'elements', |
881 | 881 | 'text' => array(), |
882 | 882 | ); |
883 | 883 | |
884 | - $Block['element']['text'][0]['text'] []= array( |
|
884 | + $Block['element']['text'][0]['text'] [] = array( |
|
885 | 885 | 'name' => 'tr', |
886 | 886 | 'handler' => 'elements', |
887 | 887 | 'text' => $HeaderElements, |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | ); |
927 | 927 | } |
928 | 928 | |
929 | - $Elements []= $Element; |
|
929 | + $Elements [] = $Element; |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | $Element = array( |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | 'text' => $Elements, |
936 | 936 | ); |
937 | 937 | |
938 | - $Block['element']['text'][1]['text'] []= $Element; |
|
938 | + $Block['element']['text'][1]['text'] [] = $Element; |
|
939 | 939 | |
940 | 940 | return $Block; |
941 | 941 | } |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | { |
1006 | 1006 | $Inline = $this->{'inline'.$inlineType}($Excerpt); |
1007 | 1007 | |
1008 | - if ( ! isset($Inline)) |
|
1008 | + if (!isset($Inline)) |
|
1009 | 1009 | { |
1010 | 1010 | continue; |
1011 | 1011 | } |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | continue; |
1016 | 1016 | } |
1017 | 1017 | |
1018 | - if ( ! isset($Inline['position'])) |
|
1018 | + if (!isset($Inline['position'])) |
|
1019 | 1019 | { |
1020 | 1020 | $Inline['position'] = $markerPosition; |
1021 | 1021 | } |
@@ -1037,7 +1037,7 @@ discard block |
||
1037 | 1037 | |
1038 | 1038 | $unexaminedText = substr($excerpt, 1); |
1039 | 1039 | |
1040 | - $markerPosition ++; |
|
1040 | + $markerPosition++; |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | $markup .= $this->unmarkedText($text); |
@@ -1075,9 +1075,9 @@ discard block |
||
1075 | 1075 | { |
1076 | 1076 | $url = $matches[1]; |
1077 | 1077 | |
1078 | - if ( ! isset($matches[2])) |
|
1078 | + if (!isset($matches[2])) |
|
1079 | 1079 | { |
1080 | - $url = 'mailto:' . $url; |
|
1080 | + $url = 'mailto:'.$url; |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | return array( |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | |
1096 | 1096 | protected function inlineEmphasis($Excerpt) |
1097 | 1097 | { |
1098 | - if ( ! isset($Excerpt['text'][1])) |
|
1098 | + if (!isset($Excerpt['text'][1])) |
|
1099 | 1099 | { |
1100 | 1100 | return; |
1101 | 1101 | } |
@@ -1138,12 +1138,12 @@ discard block |
||
1138 | 1138 | |
1139 | 1139 | protected function inlineImage($Excerpt) |
1140 | 1140 | { |
1141 | - if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') |
|
1141 | + if (!isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') |
|
1142 | 1142 | { |
1143 | 1143 | return; |
1144 | 1144 | } |
1145 | 1145 | |
1146 | - $Excerpt['text']= substr($Excerpt['text'], 1); |
|
1146 | + $Excerpt['text'] = substr($Excerpt['text'], 1); |
|
1147 | 1147 | |
1148 | 1148 | $Link = $this->inlineLink($Excerpt); |
1149 | 1149 | |
@@ -1224,7 +1224,7 @@ discard block |
||
1224 | 1224 | $definition = strtolower($Element['text']); |
1225 | 1225 | } |
1226 | 1226 | |
1227 | - if ( ! isset($this->DefinitionData['Reference'][$definition])) |
|
1227 | + if (!isset($this->DefinitionData['Reference'][$definition])) |
|
1228 | 1228 | { |
1229 | 1229 | return; |
1230 | 1230 | } |
@@ -1277,7 +1277,7 @@ discard block |
||
1277 | 1277 | |
1278 | 1278 | protected function inlineSpecialCharacter($Excerpt) |
1279 | 1279 | { |
1280 | - if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text'])) |
|
1280 | + if ($Excerpt['text'][0] === '&' and !preg_match('/^&#?\w+;/', $Excerpt['text'])) |
|
1281 | 1281 | { |
1282 | 1282 | return array( |
1283 | 1283 | 'markup' => '&', |
@@ -1298,7 +1298,7 @@ discard block |
||
1298 | 1298 | |
1299 | 1299 | protected function inlineStrikethrough($Excerpt) |
1300 | 1300 | { |
1301 | - if ( ! isset($Excerpt['text'][1])) |
|
1301 | + if (!isset($Excerpt['text'][1])) |
|
1302 | 1302 | { |
1303 | 1303 | return; |
1304 | 1304 | } |
@@ -1318,7 +1318,7 @@ discard block |
||
1318 | 1318 | |
1319 | 1319 | protected function inlineUrl($Excerpt) |
1320 | 1320 | { |
1321 | - if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') |
|
1321 | + if ($this->urlsLinked !== true or !isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') |
|
1322 | 1322 | { |
1323 | 1323 | return; |
1324 | 1324 | } |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | |
1433 | 1433 | foreach ($Elements as $Element) |
1434 | 1434 | { |
1435 | - $markup .= "\n" . $this->element($Element); |
|
1435 | + $markup .= "\n".$this->element($Element); |
|
1436 | 1436 | } |
1437 | 1437 | |
1438 | 1438 | $markup .= "\n"; |
@@ -1448,7 +1448,7 @@ discard block |
||
1448 | 1448 | |
1449 | 1449 | $trimmedMarkup = trim($markup); |
1450 | 1450 | |
1451 | - if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>') |
|
1451 | + if (!in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>') |
|
1452 | 1452 | { |
1453 | 1453 | $markup = $trimmedMarkup; |
1454 | 1454 | $markup = substr($markup, 3); |
@@ -1524,8 +1524,8 @@ discard block |
||
1524 | 1524 | protected $textLevelElements = array( |
1525 | 1525 | 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont', |
1526 | 1526 | 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing', |
1527 | - 'i', 'rp', 'del', 'code', 'strike', 'marquee', |
|
1528 | - 'q', 'rt', 'ins', 'font', 'strong', |
|
1527 | + 'i', 'rp', 'del', 'code', 'strike', 'marquee', |
|
1528 | + 'q', 'rt', 'ins', 'font', 'strong', |
|
1529 | 1529 | 's', 'tt', 'sub', 'mark', |
1530 | 1530 | 'u', 'xm', 'sup', 'nobr', |
1531 | 1531 | 'var', 'ruby', |
@@ -178,8 +178,7 @@ discard block |
||
178 | 178 | $CurrentBlock = $Block; |
179 | 179 | |
180 | 180 | continue; |
181 | - } |
|
182 | - else |
|
181 | + } else |
|
183 | 182 | { |
184 | 183 | if (method_exists($this, 'block'.$CurrentBlock['type'].'Complete')) |
185 | 184 | { |
@@ -240,8 +239,7 @@ discard block |
||
240 | 239 | if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) |
241 | 240 | { |
242 | 241 | $CurrentBlock['element']['text'] .= "\n".$text; |
243 | - } |
|
244 | - else |
|
242 | + } else |
|
245 | 243 | { |
246 | 244 | $Blocks []= $CurrentBlock; |
247 | 245 | |
@@ -696,8 +694,7 @@ discard block |
||
696 | 694 | |
697 | 695 | $Block['void'] = true; |
698 | 696 | } |
699 | - } |
|
700 | - else |
|
697 | + } else |
|
701 | 698 | { |
702 | 699 | if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) |
703 | 700 | { |
@@ -721,18 +718,21 @@ discard block |
||
721 | 718 | return; |
722 | 719 | } |
723 | 720 | |
724 | - if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open |
|
721 | + if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) { |
|
722 | + # open |
|
725 | 723 | { |
726 | 724 | $Block['depth'] ++; |
727 | 725 | } |
726 | + } |
|
728 | 727 | |
729 | - if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close |
|
728 | + if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) { |
|
729 | + # close |
|
730 | 730 | { |
731 | 731 | if ($Block['depth'] > 0) |
732 | 732 | { |
733 | 733 | $Block['depth'] --; |
734 | - } |
|
735 | - else |
|
734 | + } |
|
735 | + } else |
|
736 | 736 | { |
737 | 737 | $Block['closed'] = true; |
738 | 738 | } |
@@ -1010,10 +1010,12 @@ discard block |
||
1010 | 1010 | continue; |
1011 | 1011 | } |
1012 | 1012 | |
1013 | - if (isset($Inline['position']) and $Inline['position'] > $markerPosition) # position is ahead of marker |
|
1013 | + if (isset($Inline['position']) and $Inline['position'] > $markerPosition) { |
|
1014 | + # position is ahead of marker |
|
1014 | 1015 | { |
1015 | 1016 | continue; |
1016 | 1017 | } |
1018 | + } |
|
1017 | 1019 | |
1018 | 1020 | if ( ! isset($Inline['position'])) |
1019 | 1021 | { |
@@ -1105,12 +1107,10 @@ discard block |
||
1105 | 1107 | if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) |
1106 | 1108 | { |
1107 | 1109 | $emphasis = 'strong'; |
1108 | - } |
|
1109 | - elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1110 | + } elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1110 | 1111 | { |
1111 | 1112 | $emphasis = 'em'; |
1112 | - } |
|
1113 | - else |
|
1113 | + } else |
|
1114 | 1114 | { |
1115 | 1115 | return; |
1116 | 1116 | } |
@@ -1193,8 +1193,7 @@ discard block |
||
1193 | 1193 | $extent += strlen($matches[0]); |
1194 | 1194 | |
1195 | 1195 | $remainder = substr($remainder, $extent); |
1196 | - } |
|
1197 | - else |
|
1196 | + } else |
|
1198 | 1197 | { |
1199 | 1198 | return; |
1200 | 1199 | } |
@@ -1209,8 +1208,7 @@ discard block |
||
1209 | 1208 | } |
1210 | 1209 | |
1211 | 1210 | $extent += strlen($matches[0]); |
1212 | - } |
|
1213 | - else |
|
1211 | + } else |
|
1214 | 1212 | { |
1215 | 1213 | if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) |
1216 | 1214 | { |
@@ -1218,8 +1216,7 @@ discard block |
||
1218 | 1216 | $definition = strtolower($definition); |
1219 | 1217 | |
1220 | 1218 | $extent += strlen($matches[0]); |
1221 | - } |
|
1222 | - else |
|
1219 | + } else |
|
1223 | 1220 | { |
1224 | 1221 | $definition = strtolower($Element['text']); |
1225 | 1222 | } |
@@ -1372,8 +1369,7 @@ discard block |
||
1372 | 1369 | if ($this->breaksEnabled) |
1373 | 1370 | { |
1374 | 1371 | $text = preg_replace('/[ ]*\n/', "<br />\n", $text); |
1375 | - } |
|
1376 | - else |
|
1372 | + } else |
|
1377 | 1373 | { |
1378 | 1374 | $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text); |
1379 | 1375 | $text = str_replace(" \n", "\n", $text); |
@@ -1410,15 +1406,13 @@ discard block |
||
1410 | 1406 | if (isset($Element['handler'])) |
1411 | 1407 | { |
1412 | 1408 | $markup .= $this->{$Element['handler']}($Element['text']); |
1413 | - } |
|
1414 | - else |
|
1409 | + } else |
|
1415 | 1410 | { |
1416 | 1411 | $markup .= $Element['text']; |
1417 | 1412 | } |
1418 | 1413 | |
1419 | 1414 | $markup .= '</'.$Element['name'].'>'; |
1420 | - } |
|
1421 | - else |
|
1415 | + } else |
|
1422 | 1416 | { |
1423 | 1417 | $markup .= ' />'; |
1424 | 1418 | } |
@@ -1531,8 +1531,8 @@ |
||
1531 | 1531 | 'q', 'rt', 'ins', 'font', 'strong', |
1532 | 1532 | 's', 'tt', 'sub', 'mark', |
1533 | 1533 | 'u', 'xm', 'sup', 'nobr', |
1534 | - 'var', 'ruby', |
|
1535 | - 'wbr', 'span', |
|
1536 | - 'time', |
|
1534 | + 'var', 'ruby', |
|
1535 | + 'wbr', 'span', |
|
1536 | + 'time', |
|
1537 | 1537 | ); |
1538 | 1538 | } |
1539 | 1539 | \ No newline at end of file |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | foreach ($parts as $part) |
143 | 143 | { |
144 | - $shortage = 4 - mb_strlen($line, 'utf-8') % 4; |
|
144 | + $shortage = 4 - mb_strlen($line, 'utf-8')%4; |
|
145 | 145 | |
146 | 146 | $line .= str_repeat(' ', $shortage); |
147 | 147 | $line .= $part; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | |
153 | 153 | while (isset($line[$indent]) and $line[$indent] === ' ') |
154 | 154 | { |
155 | - $indent ++; |
|
155 | + $indent++; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | $text = $indent > 0 ? substr($line, $indent) : $line; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | { |
195 | 195 | foreach ($this->BlockTypes[$marker] as $blockType) |
196 | 196 | { |
197 | - $blockTypes []= $blockType; |
|
197 | + $blockTypes [] = $blockType; |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | { |
210 | 210 | $Block['type'] = $blockType; |
211 | 211 | |
212 | - if ( ! isset($Block['identified'])) |
|
212 | + if (!isset($Block['identified'])) |
|
213 | 213 | { |
214 | - $Blocks []= $CurrentBlock; |
|
214 | + $Blocks [] = $CurrentBlock; |
|
215 | 215 | |
216 | 216 | $Block['identified'] = true; |
217 | 217 | } |
@@ -229,13 +229,13 @@ discard block |
||
229 | 229 | |
230 | 230 | # ~ |
231 | 231 | |
232 | - if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) |
|
232 | + if (isset($CurrentBlock) and !isset($CurrentBlock['type']) and !isset($CurrentBlock['interrupted'])) |
|
233 | 233 | { |
234 | 234 | $CurrentBlock['element']['text'] .= "\n".$text; |
235 | 235 | } |
236 | 236 | else |
237 | 237 | { |
238 | - $Blocks []= $CurrentBlock; |
|
238 | + $Blocks [] = $CurrentBlock; |
|
239 | 239 | |
240 | 240 | $CurrentBlock = $this->paragraph($Line); |
241 | 241 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | |
253 | 253 | # ~ |
254 | 254 | |
255 | - $Blocks []= $CurrentBlock; |
|
255 | + $Blocks [] = $CurrentBlock; |
|
256 | 256 | |
257 | 257 | unset($Blocks[0]); |
258 | 258 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | |
294 | 294 | protected function blockCode($Line, $Block = null) |
295 | 295 | { |
296 | - if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted'])) |
|
296 | + if (isset($Block) and !isset($Block['type']) and !isset($Block['interrupted'])) |
|
297 | 297 | { |
298 | 298 | return; |
299 | 299 | } |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | - $Block['markup'] .= "\n" . $Line['body']; |
|
384 | + $Block['markup'] .= "\n".$Line['body']; |
|
385 | 385 | |
386 | 386 | if (preg_match('/-->$/', $Line['text'])) |
387 | 387 | { |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | return $Block; |
449 | 449 | } |
450 | 450 | |
451 | - $Block['element']['text']['text'] .= "\n".$Line['body'];; |
|
451 | + $Block['element']['text']['text'] .= "\n".$Line['body']; ; |
|
452 | 452 | |
453 | 453 | return $Block; |
454 | 454 | } |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | |
476 | 476 | while (isset($Line['text'][$level]) and $Line['text'][$level] === '#') |
477 | 477 | { |
478 | - $level ++; |
|
478 | + $level++; |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | if ($level > 6) |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | |
488 | 488 | $Block = array( |
489 | 489 | 'element' => array( |
490 | - 'name' => 'h' . min(6, $level), |
|
490 | + 'name' => 'h'.min(6, $level), |
|
491 | 491 | 'text' => $text, |
492 | 492 | 'handler' => 'line', |
493 | 493 | ), |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | ), |
524 | 524 | ); |
525 | 525 | |
526 | - $Block['element']['text'] []= & $Block['li']; |
|
526 | + $Block['element']['text'] [] = & $Block['li']; |
|
527 | 527 | |
528 | 528 | return $Block; |
529 | 529 | } |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | { |
536 | 536 | if (isset($Block['interrupted'])) |
537 | 537 | { |
538 | - $Block['li']['text'] []= ''; |
|
538 | + $Block['li']['text'] [] = ''; |
|
539 | 539 | |
540 | 540 | unset($Block['interrupted']); |
541 | 541 | } |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | ), |
553 | 553 | ); |
554 | 554 | |
555 | - $Block['element']['text'] []= & $Block['li']; |
|
555 | + $Block['element']['text'] [] = & $Block['li']; |
|
556 | 556 | |
557 | 557 | return $Block; |
558 | 558 | } |
@@ -562,22 +562,22 @@ discard block |
||
562 | 562 | return $Block; |
563 | 563 | } |
564 | 564 | |
565 | - if ( ! isset($Block['interrupted'])) |
|
565 | + if (!isset($Block['interrupted'])) |
|
566 | 566 | { |
567 | 567 | $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); |
568 | 568 | |
569 | - $Block['li']['text'] []= $text; |
|
569 | + $Block['li']['text'] [] = $text; |
|
570 | 570 | |
571 | 571 | return $Block; |
572 | 572 | } |
573 | 573 | |
574 | 574 | if ($Line['indent'] > 0) |
575 | 575 | { |
576 | - $Block['li']['text'] []= ''; |
|
576 | + $Block['li']['text'] [] = ''; |
|
577 | 577 | |
578 | 578 | $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); |
579 | 579 | |
580 | - $Block['li']['text'] []= $text; |
|
580 | + $Block['li']['text'] [] = $text; |
|
581 | 581 | |
582 | 582 | unset($Block['interrupted']); |
583 | 583 | |
@@ -610,19 +610,19 @@ discard block |
||
610 | 610 | { |
611 | 611 | if (isset($Block['interrupted'])) |
612 | 612 | { |
613 | - $Block['element']['text'] []= ''; |
|
613 | + $Block['element']['text'] [] = ''; |
|
614 | 614 | |
615 | 615 | unset($Block['interrupted']); |
616 | 616 | } |
617 | 617 | |
618 | - $Block['element']['text'] []= $matches[1]; |
|
618 | + $Block['element']['text'] [] = $matches[1]; |
|
619 | 619 | |
620 | 620 | return $Block; |
621 | 621 | } |
622 | 622 | |
623 | - if ( ! isset($Block['interrupted'])) |
|
623 | + if (!isset($Block['interrupted'])) |
|
624 | 624 | { |
625 | - $Block['element']['text'] []= $Line['text']; |
|
625 | + $Block['element']['text'] [] = $Line['text']; |
|
626 | 626 | |
627 | 627 | return $Block; |
628 | 628 | } |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | |
651 | 651 | protected function blockSetextHeader($Line, array $Block = null) |
652 | 652 | { |
653 | - if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
653 | + if (!isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
654 | 654 | { |
655 | 655 | return; |
656 | 656 | } |
@@ -727,14 +727,14 @@ discard block |
||
727 | 727 | |
728 | 728 | if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open |
729 | 729 | { |
730 | - $Block['depth'] ++; |
|
730 | + $Block['depth']++; |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close |
734 | 734 | { |
735 | 735 | if ($Block['depth'] > 0) |
736 | 736 | { |
737 | - $Block['depth'] --; |
|
737 | + $Block['depth']--; |
|
738 | 738 | } |
739 | 739 | else |
740 | 740 | { |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | |
789 | 789 | protected function blockTable($Line, array $Block = null) |
790 | 790 | { |
791 | - if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
791 | + if (!isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
792 | 792 | { |
793 | 793 | return; |
794 | 794 | } |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | $alignment = $alignment === 'left' ? 'center' : 'right'; |
826 | 826 | } |
827 | 827 | |
828 | - $alignments []= $alignment; |
|
828 | + $alignments [] = $alignment; |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | # ~ |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | ); |
859 | 859 | } |
860 | 860 | |
861 | - $HeaderElements []= $HeaderElement; |
|
861 | + $HeaderElements [] = $HeaderElement; |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | # ~ |
@@ -872,18 +872,18 @@ discard block |
||
872 | 872 | ), |
873 | 873 | ); |
874 | 874 | |
875 | - $Block['element']['text'] []= array( |
|
875 | + $Block['element']['text'] [] = array( |
|
876 | 876 | 'name' => 'thead', |
877 | 877 | 'handler' => 'elements', |
878 | 878 | ); |
879 | 879 | |
880 | - $Block['element']['text'] []= array( |
|
880 | + $Block['element']['text'] [] = array( |
|
881 | 881 | 'name' => 'tbody', |
882 | 882 | 'handler' => 'elements', |
883 | 883 | 'text' => array(), |
884 | 884 | ); |
885 | 885 | |
886 | - $Block['element']['text'][0]['text'] []= array( |
|
886 | + $Block['element']['text'][0]['text'] [] = array( |
|
887 | 887 | 'name' => 'tr', |
888 | 888 | 'handler' => 'elements', |
889 | 889 | 'text' => $HeaderElements, |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | ); |
929 | 929 | } |
930 | 930 | |
931 | - $Elements []= $Element; |
|
931 | + $Elements [] = $Element; |
|
932 | 932 | } |
933 | 933 | |
934 | 934 | $Element = array( |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | 'text' => $Elements, |
938 | 938 | ); |
939 | 939 | |
940 | - $Block['element']['text'][1]['text'] []= $Element; |
|
940 | + $Block['element']['text'][1]['text'] [] = $Element; |
|
941 | 941 | |
942 | 942 | return $Block; |
943 | 943 | } |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | { |
1006 | 1006 | $Inline = $this->{'inline'.$inlineType}($Excerpt); |
1007 | 1007 | |
1008 | - if ( ! isset($Inline)) |
|
1008 | + if (!isset($Inline)) |
|
1009 | 1009 | { |
1010 | 1010 | continue; |
1011 | 1011 | } |
@@ -1019,7 +1019,7 @@ discard block |
||
1019 | 1019 | |
1020 | 1020 | # sets a default inline position |
1021 | 1021 | |
1022 | - if ( ! isset($Inline['position'])) |
|
1022 | + if (!isset($Inline['position'])) |
|
1023 | 1023 | { |
1024 | 1024 | $Inline['position'] = $markerPosition; |
1025 | 1025 | } |
@@ -1083,9 +1083,9 @@ discard block |
||
1083 | 1083 | { |
1084 | 1084 | $url = $matches[1]; |
1085 | 1085 | |
1086 | - if ( ! isset($matches[2])) |
|
1086 | + if (!isset($matches[2])) |
|
1087 | 1087 | { |
1088 | - $url = 'mailto:' . $url; |
|
1088 | + $url = 'mailto:'.$url; |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | return array( |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | |
1104 | 1104 | protected function inlineEmphasis($Excerpt) |
1105 | 1105 | { |
1106 | - if ( ! isset($Excerpt['text'][1])) |
|
1106 | + if (!isset($Excerpt['text'][1])) |
|
1107 | 1107 | { |
1108 | 1108 | return; |
1109 | 1109 | } |
@@ -1146,12 +1146,12 @@ discard block |
||
1146 | 1146 | |
1147 | 1147 | protected function inlineImage($Excerpt) |
1148 | 1148 | { |
1149 | - if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') |
|
1149 | + if (!isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') |
|
1150 | 1150 | { |
1151 | 1151 | return; |
1152 | 1152 | } |
1153 | 1153 | |
1154 | - $Excerpt['text']= substr($Excerpt['text'], 1); |
|
1154 | + $Excerpt['text'] = substr($Excerpt['text'], 1); |
|
1155 | 1155 | |
1156 | 1156 | $Link = $this->inlineLink($Excerpt); |
1157 | 1157 | |
@@ -1232,7 +1232,7 @@ discard block |
||
1232 | 1232 | $definition = strtolower($Element['text']); |
1233 | 1233 | } |
1234 | 1234 | |
1235 | - if ( ! isset($this->DefinitionData['Reference'][$definition])) |
|
1235 | + if (!isset($this->DefinitionData['Reference'][$definition])) |
|
1236 | 1236 | { |
1237 | 1237 | return; |
1238 | 1238 | } |
@@ -1285,7 +1285,7 @@ discard block |
||
1285 | 1285 | |
1286 | 1286 | protected function inlineSpecialCharacter($Excerpt) |
1287 | 1287 | { |
1288 | - if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text'])) |
|
1288 | + if ($Excerpt['text'][0] === '&' and !preg_match('/^&#?\w+;/', $Excerpt['text'])) |
|
1289 | 1289 | { |
1290 | 1290 | return array( |
1291 | 1291 | 'markup' => '&', |
@@ -1306,7 +1306,7 @@ discard block |
||
1306 | 1306 | |
1307 | 1307 | protected function inlineStrikethrough($Excerpt) |
1308 | 1308 | { |
1309 | - if ( ! isset($Excerpt['text'][1])) |
|
1309 | + if (!isset($Excerpt['text'][1])) |
|
1310 | 1310 | { |
1311 | 1311 | return; |
1312 | 1312 | } |
@@ -1326,7 +1326,7 @@ discard block |
||
1326 | 1326 | |
1327 | 1327 | protected function inlineUrl($Excerpt) |
1328 | 1328 | { |
1329 | - if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') |
|
1329 | + if ($this->urlsLinked !== true or !isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') |
|
1330 | 1330 | { |
1331 | 1331 | return; |
1332 | 1332 | } |
@@ -1435,7 +1435,7 @@ discard block |
||
1435 | 1435 | |
1436 | 1436 | foreach ($Elements as $Element) |
1437 | 1437 | { |
1438 | - $markup .= "\n" . $this->element($Element); |
|
1438 | + $markup .= "\n".$this->element($Element); |
|
1439 | 1439 | } |
1440 | 1440 | |
1441 | 1441 | $markup .= "\n"; |
@@ -1451,7 +1451,7 @@ discard block |
||
1451 | 1451 | |
1452 | 1452 | $trimmedMarkup = trim($markup); |
1453 | 1453 | |
1454 | - if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>') |
|
1454 | + if (!in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>') |
|
1455 | 1455 | { |
1456 | 1456 | $markup = $trimmedMarkup; |
1457 | 1457 | $markup = substr($markup, 3); |
@@ -1527,8 +1527,8 @@ discard block |
||
1527 | 1527 | protected $textLevelElements = array( |
1528 | 1528 | 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont', |
1529 | 1529 | 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing', |
1530 | - 'i', 'rp', 'del', 'code', 'strike', 'marquee', |
|
1531 | - 'q', 'rt', 'ins', 'font', 'strong', |
|
1530 | + 'i', 'rp', 'del', 'code', 'strike', 'marquee', |
|
1531 | + 'q', 'rt', 'ins', 'font', 'strong', |
|
1532 | 1532 | 's', 'tt', 'sub', 'mark', |
1533 | 1533 | 'u', 'xm', 'sup', 'nobr', |
1534 | 1534 | 'var', 'ruby', |
@@ -172,8 +172,7 @@ discard block |
||
172 | 172 | $CurrentBlock = $Block; |
173 | 173 | |
174 | 174 | continue; |
175 | - } |
|
176 | - else |
|
175 | + } else |
|
177 | 176 | { |
178 | 177 | if ($this->isBlockCompletable($CurrentBlock['type'])) |
179 | 178 | { |
@@ -232,8 +231,7 @@ discard block |
||
232 | 231 | if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) |
233 | 232 | { |
234 | 233 | $CurrentBlock['element']['text'] .= "\n".$text; |
235 | - } |
|
236 | - else |
|
234 | + } else |
|
237 | 235 | { |
238 | 236 | $Blocks []= $CurrentBlock; |
239 | 237 | |
@@ -700,8 +698,7 @@ discard block |
||
700 | 698 | |
701 | 699 | $Block['void'] = true; |
702 | 700 | } |
703 | - } |
|
704 | - else |
|
701 | + } else |
|
705 | 702 | { |
706 | 703 | if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) |
707 | 704 | { |
@@ -725,18 +722,21 @@ discard block |
||
725 | 722 | return; |
726 | 723 | } |
727 | 724 | |
728 | - if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open |
|
725 | + if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) { |
|
726 | + # open |
|
729 | 727 | { |
730 | 728 | $Block['depth'] ++; |
731 | 729 | } |
730 | + } |
|
732 | 731 | |
733 | - if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close |
|
732 | + if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) { |
|
733 | + # close |
|
734 | 734 | { |
735 | 735 | if ($Block['depth'] > 0) |
736 | 736 | { |
737 | 737 | $Block['depth'] --; |
738 | - } |
|
739 | - else |
|
738 | + } |
|
739 | + } else |
|
740 | 740 | { |
741 | 741 | $Block['closed'] = true; |
742 | 742 | } |
@@ -1113,12 +1113,10 @@ discard block |
||
1113 | 1113 | if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) |
1114 | 1114 | { |
1115 | 1115 | $emphasis = 'strong'; |
1116 | - } |
|
1117 | - elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1116 | + } elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1118 | 1117 | { |
1119 | 1118 | $emphasis = 'em'; |
1120 | - } |
|
1121 | - else |
|
1119 | + } else |
|
1122 | 1120 | { |
1123 | 1121 | return; |
1124 | 1122 | } |
@@ -1201,8 +1199,7 @@ discard block |
||
1201 | 1199 | $extent += strlen($matches[0]); |
1202 | 1200 | |
1203 | 1201 | $remainder = substr($remainder, $extent); |
1204 | - } |
|
1205 | - else |
|
1202 | + } else |
|
1206 | 1203 | { |
1207 | 1204 | return; |
1208 | 1205 | } |
@@ -1217,8 +1214,7 @@ discard block |
||
1217 | 1214 | } |
1218 | 1215 | |
1219 | 1216 | $extent += strlen($matches[0]); |
1220 | - } |
|
1221 | - else |
|
1217 | + } else |
|
1222 | 1218 | { |
1223 | 1219 | if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) |
1224 | 1220 | { |
@@ -1226,8 +1222,7 @@ discard block |
||
1226 | 1222 | $definition = strtolower($definition); |
1227 | 1223 | |
1228 | 1224 | $extent += strlen($matches[0]); |
1229 | - } |
|
1230 | - else |
|
1225 | + } else |
|
1231 | 1226 | { |
1232 | 1227 | $definition = strtolower($Element['text']); |
1233 | 1228 | } |
@@ -1375,8 +1370,7 @@ discard block |
||
1375 | 1370 | if ($this->breaksEnabled) |
1376 | 1371 | { |
1377 | 1372 | $text = preg_replace('/[ ]*\n/', "<br />\n", $text); |
1378 | - } |
|
1379 | - else |
|
1373 | + } else |
|
1380 | 1374 | { |
1381 | 1375 | $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text); |
1382 | 1376 | $text = str_replace(" \n", "\n", $text); |
@@ -1413,15 +1407,13 @@ discard block |
||
1413 | 1407 | if (isset($Element['handler'])) |
1414 | 1408 | { |
1415 | 1409 | $markup .= $this->{$Element['handler']}($Element['text']); |
1416 | - } |
|
1417 | - else |
|
1410 | + } else |
|
1418 | 1411 | { |
1419 | 1412 | $markup .= $Element['text']; |
1420 | 1413 | } |
1421 | 1414 | |
1422 | 1415 | $markup .= '</'.$Element['name'].'>'; |
1423 | - } |
|
1424 | - else |
|
1416 | + } else |
|
1425 | 1417 | { |
1426 | 1418 | $markup .= ' />'; |
1427 | 1419 | } |
@@ -2,68 +2,68 @@ |
||
2 | 2 | |
3 | 3 | if ( !class_exists('Puc_v4p4_Utils', false) ): |
4 | 4 | |
5 | - class Puc_v4p4_Utils { |
|
6 | - /** |
|
7 | - * Get a value from a nested array or object based on a path. |
|
8 | - * |
|
9 | - * @param array|object|null $collection Get an entry from this array. |
|
10 | - * @param array|string $path A list of array keys in hierarchy order, or a string path like "foo.bar.baz". |
|
11 | - * @param mixed $default The value to return if the specified path is not found. |
|
12 | - * @param string $separator Path element separator. Only applies to string paths. |
|
13 | - * @return mixed |
|
14 | - */ |
|
15 | - public static function get($collection, $path, $default = null, $separator = '.') { |
|
16 | - if ( is_string($path) ) { |
|
17 | - $path = explode($separator, $path); |
|
18 | - } |
|
5 | + class Puc_v4p4_Utils { |
|
6 | + /** |
|
7 | + * Get a value from a nested array or object based on a path. |
|
8 | + * |
|
9 | + * @param array|object|null $collection Get an entry from this array. |
|
10 | + * @param array|string $path A list of array keys in hierarchy order, or a string path like "foo.bar.baz". |
|
11 | + * @param mixed $default The value to return if the specified path is not found. |
|
12 | + * @param string $separator Path element separator. Only applies to string paths. |
|
13 | + * @return mixed |
|
14 | + */ |
|
15 | + public static function get($collection, $path, $default = null, $separator = '.') { |
|
16 | + if ( is_string($path) ) { |
|
17 | + $path = explode($separator, $path); |
|
18 | + } |
|
19 | 19 | |
20 | - //Follow the $path into $input as far as possible. |
|
21 | - $currentValue = $collection; |
|
22 | - foreach ($path as $node) { |
|
23 | - if ( is_array($currentValue) && isset($currentValue[$node]) ) { |
|
24 | - $currentValue = $currentValue[$node]; |
|
25 | - } else if ( is_object($currentValue) && isset($currentValue->$node) ) { |
|
26 | - $currentValue = $currentValue->$node; |
|
27 | - } else { |
|
28 | - return $default; |
|
29 | - } |
|
30 | - } |
|
20 | + //Follow the $path into $input as far as possible. |
|
21 | + $currentValue = $collection; |
|
22 | + foreach ($path as $node) { |
|
23 | + if ( is_array($currentValue) && isset($currentValue[$node]) ) { |
|
24 | + $currentValue = $currentValue[$node]; |
|
25 | + } else if ( is_object($currentValue) && isset($currentValue->$node) ) { |
|
26 | + $currentValue = $currentValue->$node; |
|
27 | + } else { |
|
28 | + return $default; |
|
29 | + } |
|
30 | + } |
|
31 | 31 | |
32 | - return $currentValue; |
|
33 | - } |
|
32 | + return $currentValue; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Get the first array element that is not empty. |
|
37 | - * |
|
38 | - * @param array $values |
|
39 | - * @param mixed|null $default Returns this value if there are no non-empty elements. |
|
40 | - * @return mixed|null |
|
41 | - */ |
|
42 | - public static function findNotEmpty($values, $default = null) { |
|
43 | - if ( empty($values) ) { |
|
44 | - return $default; |
|
45 | - } |
|
35 | + /** |
|
36 | + * Get the first array element that is not empty. |
|
37 | + * |
|
38 | + * @param array $values |
|
39 | + * @param mixed|null $default Returns this value if there are no non-empty elements. |
|
40 | + * @return mixed|null |
|
41 | + */ |
|
42 | + public static function findNotEmpty($values, $default = null) { |
|
43 | + if ( empty($values) ) { |
|
44 | + return $default; |
|
45 | + } |
|
46 | 46 | |
47 | - foreach ($values as $value) { |
|
48 | - if ( !empty($value) ) { |
|
49 | - return $value; |
|
50 | - } |
|
51 | - } |
|
47 | + foreach ($values as $value) { |
|
48 | + if ( !empty($value) ) { |
|
49 | + return $value; |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - return $default; |
|
54 | - } |
|
53 | + return $default; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Check if the input string starts with the specified prefix. |
|
58 | - * |
|
59 | - * @param string $input |
|
60 | - * @param string $prefix |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public static function startsWith($input, $prefix) { |
|
64 | - $length = strlen($prefix); |
|
65 | - return (substr($input, 0, $length) === $prefix); |
|
66 | - } |
|
67 | - } |
|
56 | + /** |
|
57 | + * Check if the input string starts with the specified prefix. |
|
58 | + * |
|
59 | + * @param string $input |
|
60 | + * @param string $prefix |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public static function startsWith($input, $prefix) { |
|
64 | + $length = strlen($prefix); |
|
65 | + return (substr($input, 0, $length) === $prefix); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | endif; |
70 | 70 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( !class_exists('Puc_v4p4_Utils', false) ): |
|
3 | +if (!class_exists('Puc_v4p4_Utils', false)): |
|
4 | 4 | |
5 | 5 | class Puc_v4p4_Utils { |
6 | 6 | /** |
@@ -13,16 +13,16 @@ discard block |
||
13 | 13 | * @return mixed |
14 | 14 | */ |
15 | 15 | public static function get($collection, $path, $default = null, $separator = '.') { |
16 | - if ( is_string($path) ) { |
|
16 | + if (is_string($path)) { |
|
17 | 17 | $path = explode($separator, $path); |
18 | 18 | } |
19 | 19 | |
20 | 20 | //Follow the $path into $input as far as possible. |
21 | 21 | $currentValue = $collection; |
22 | 22 | foreach ($path as $node) { |
23 | - if ( is_array($currentValue) && isset($currentValue[$node]) ) { |
|
23 | + if (is_array($currentValue) && isset($currentValue[$node])) { |
|
24 | 24 | $currentValue = $currentValue[$node]; |
25 | - } else if ( is_object($currentValue) && isset($currentValue->$node) ) { |
|
25 | + } else if (is_object($currentValue) && isset($currentValue->$node)) { |
|
26 | 26 | $currentValue = $currentValue->$node; |
27 | 27 | } else { |
28 | 28 | return $default; |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | * @return mixed|null |
41 | 41 | */ |
42 | 42 | public static function findNotEmpty($values, $default = null) { |
43 | - if ( empty($values) ) { |
|
43 | + if (empty($values)) { |
|
44 | 44 | return $default; |
45 | 45 | } |
46 | 46 | |
47 | 47 | foreach ($values as $value) { |
48 | - if ( !empty($value) ) { |
|
48 | + if (!empty($value)) { |
|
49 | 49 | return $value; |
50 | 50 | } |
51 | 51 | } |
@@ -1,27 +1,27 @@ |
||
1 | 1 | <?php |
2 | 2 | if ( !interface_exists('Puc_v4p4_Vcs_BaseChecker', false) ): |
3 | 3 | |
4 | - interface Puc_v4p4_Vcs_BaseChecker { |
|
5 | - /** |
|
6 | - * Set the repository branch to use for updates. Defaults to 'master'. |
|
7 | - * |
|
8 | - * @param string $branch |
|
9 | - * @return $this |
|
10 | - */ |
|
11 | - public function setBranch($branch); |
|
4 | + interface Puc_v4p4_Vcs_BaseChecker { |
|
5 | + /** |
|
6 | + * Set the repository branch to use for updates. Defaults to 'master'. |
|
7 | + * |
|
8 | + * @param string $branch |
|
9 | + * @return $this |
|
10 | + */ |
|
11 | + public function setBranch($branch); |
|
12 | 12 | |
13 | - /** |
|
14 | - * Set authentication credentials. |
|
15 | - * |
|
16 | - * @param array|string $credentials |
|
17 | - * @return $this |
|
18 | - */ |
|
19 | - public function setAuthentication($credentials); |
|
13 | + /** |
|
14 | + * Set authentication credentials. |
|
15 | + * |
|
16 | + * @param array|string $credentials |
|
17 | + * @return $this |
|
18 | + */ |
|
19 | + public function setAuthentication($credentials); |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return Puc_v4p4_Vcs_Api |
|
23 | - */ |
|
24 | - public function getVcsApi(); |
|
25 | - } |
|
21 | + /** |
|
22 | + * @return Puc_v4p4_Vcs_Api |
|
23 | + */ |
|
24 | + public function getVcsApi(); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | endif; |
28 | 28 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -if ( !interface_exists('Puc_v4p4_Vcs_BaseChecker', false) ): |
|
2 | +if (!interface_exists('Puc_v4p4_Vcs_BaseChecker', false)): |
|
3 | 3 | |
4 | 4 | interface Puc_v4p4_Vcs_BaseChecker { |
5 | 5 | /** |
@@ -2,117 +2,117 @@ |
||
2 | 2 | |
3 | 3 | if ( !class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false) ): |
4 | 4 | |
5 | - class Puc_v4p4_Vcs_ThemeUpdateChecker extends Puc_v4p4_Theme_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker { |
|
6 | - /** |
|
7 | - * @var string The branch where to look for updates. Defaults to "master". |
|
8 | - */ |
|
9 | - protected $branch = 'master'; |
|
10 | - |
|
11 | - /** |
|
12 | - * @var Puc_v4p4_Vcs_Api Repository API client. |
|
13 | - */ |
|
14 | - protected $api = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Puc_v4p4_Vcs_ThemeUpdateChecker constructor. |
|
18 | - * |
|
19 | - * @param Puc_v4p4_Vcs_Api $api |
|
20 | - * @param null $stylesheet |
|
21 | - * @param null $customSlug |
|
22 | - * @param int $checkPeriod |
|
23 | - * @param string $optionName |
|
24 | - */ |
|
25 | - public function __construct($api, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') { |
|
26 | - $this->api = $api; |
|
27 | - $this->api->setHttpFilterName($this->getUniqueName('request_update_options')); |
|
28 | - |
|
29 | - parent::__construct($api->getRepositoryUrl(), $stylesheet, $customSlug, $checkPeriod, $optionName); |
|
30 | - |
|
31 | - $this->api->setSlug($this->slug); |
|
32 | - } |
|
33 | - |
|
34 | - public function requestUpdate() { |
|
35 | - $api = $this->api; |
|
36 | - $api->setLocalDirectory($this->getAbsoluteDirectoryPath()); |
|
37 | - |
|
38 | - $update = new Puc_v4p4_Theme_Update(); |
|
39 | - $update->slug = $this->slug; |
|
40 | - |
|
41 | - //Figure out which reference (tag or branch) we'll use to get the latest version of the theme. |
|
42 | - $updateSource = $api->chooseReference($this->branch); |
|
43 | - if ( $updateSource ) { |
|
44 | - $ref = $updateSource->name; |
|
45 | - $update->download_url = $updateSource->downloadUrl; |
|
46 | - } else { |
|
47 | - do_action( |
|
48 | - 'puc_api_error', |
|
49 | - new WP_Error( |
|
50 | - 'puc-no-update-source', |
|
51 | - 'Could not retrieve version information from the repository. ' |
|
52 | - . 'This usually means that the update checker either can\'t connect ' |
|
53 | - . 'to the repository or it\'s configured incorrectly.' |
|
54 | - ), |
|
55 | - null, null, $this->slug |
|
56 | - ); |
|
57 | - $ref = $this->branch; |
|
58 | - } |
|
59 | - |
|
60 | - //Get headers from the main stylesheet in this branch/tag. Its "Version" header and other metadata |
|
61 | - //are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags. |
|
62 | - $remoteHeader = $this->getFileHeader($api->getRemoteFile('style.css', $ref)); |
|
63 | - $update->version = Puc_v4p4_Utils::findNotEmpty(array( |
|
64 | - $remoteHeader['Version'], |
|
65 | - Puc_v4p4_Utils::get($updateSource, 'version'), |
|
66 | - )); |
|
67 | - |
|
68 | - //The details URL defaults to the Theme URI header or the repository URL. |
|
69 | - $update->details_url = Puc_v4p4_Utils::findNotEmpty(array( |
|
70 | - $remoteHeader['ThemeURI'], |
|
71 | - $this->theme->get('ThemeURI'), |
|
72 | - $this->metadataUrl, |
|
73 | - )); |
|
74 | - |
|
75 | - if ( empty($update->version) ) { |
|
76 | - //It looks like we didn't find a valid update after all. |
|
77 | - $update = null; |
|
78 | - } |
|
79 | - |
|
80 | - $update = $this->filterUpdateResult($update); |
|
81 | - return $update; |
|
82 | - } |
|
83 | - |
|
84 | - //FIXME: This is duplicated code. Both theme and plugin subclasses that use VCS share these methods. |
|
85 | - |
|
86 | - public function setBranch($branch) { |
|
87 | - $this->branch = $branch; |
|
88 | - return $this; |
|
89 | - } |
|
90 | - |
|
91 | - public function setAuthentication($credentials) { |
|
92 | - $this->api->setAuthentication($credentials); |
|
93 | - return $this; |
|
94 | - } |
|
95 | - |
|
96 | - public function getVcsApi() { |
|
97 | - return $this->api; |
|
98 | - } |
|
99 | - |
|
100 | - public function getUpdate() { |
|
101 | - $update = parent::getUpdate(); |
|
102 | - |
|
103 | - if ( isset($update) && !empty($update->download_url) ) { |
|
104 | - $update->download_url = $this->api->signDownloadUrl($update->download_url); |
|
105 | - } |
|
106 | - |
|
107 | - return $update; |
|
108 | - } |
|
109 | - |
|
110 | - public function onDisplayConfiguration($panel) { |
|
111 | - parent::onDisplayConfiguration($panel); |
|
112 | - $panel->row('Branch', $this->branch); |
|
113 | - $panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No'); |
|
114 | - $panel->row('API client', get_class($this->api)); |
|
115 | - } |
|
116 | - } |
|
5 | + class Puc_v4p4_Vcs_ThemeUpdateChecker extends Puc_v4p4_Theme_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker { |
|
6 | + /** |
|
7 | + * @var string The branch where to look for updates. Defaults to "master". |
|
8 | + */ |
|
9 | + protected $branch = 'master'; |
|
10 | + |
|
11 | + /** |
|
12 | + * @var Puc_v4p4_Vcs_Api Repository API client. |
|
13 | + */ |
|
14 | + protected $api = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Puc_v4p4_Vcs_ThemeUpdateChecker constructor. |
|
18 | + * |
|
19 | + * @param Puc_v4p4_Vcs_Api $api |
|
20 | + * @param null $stylesheet |
|
21 | + * @param null $customSlug |
|
22 | + * @param int $checkPeriod |
|
23 | + * @param string $optionName |
|
24 | + */ |
|
25 | + public function __construct($api, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') { |
|
26 | + $this->api = $api; |
|
27 | + $this->api->setHttpFilterName($this->getUniqueName('request_update_options')); |
|
28 | + |
|
29 | + parent::__construct($api->getRepositoryUrl(), $stylesheet, $customSlug, $checkPeriod, $optionName); |
|
30 | + |
|
31 | + $this->api->setSlug($this->slug); |
|
32 | + } |
|
33 | + |
|
34 | + public function requestUpdate() { |
|
35 | + $api = $this->api; |
|
36 | + $api->setLocalDirectory($this->getAbsoluteDirectoryPath()); |
|
37 | + |
|
38 | + $update = new Puc_v4p4_Theme_Update(); |
|
39 | + $update->slug = $this->slug; |
|
40 | + |
|
41 | + //Figure out which reference (tag or branch) we'll use to get the latest version of the theme. |
|
42 | + $updateSource = $api->chooseReference($this->branch); |
|
43 | + if ( $updateSource ) { |
|
44 | + $ref = $updateSource->name; |
|
45 | + $update->download_url = $updateSource->downloadUrl; |
|
46 | + } else { |
|
47 | + do_action( |
|
48 | + 'puc_api_error', |
|
49 | + new WP_Error( |
|
50 | + 'puc-no-update-source', |
|
51 | + 'Could not retrieve version information from the repository. ' |
|
52 | + . 'This usually means that the update checker either can\'t connect ' |
|
53 | + . 'to the repository or it\'s configured incorrectly.' |
|
54 | + ), |
|
55 | + null, null, $this->slug |
|
56 | + ); |
|
57 | + $ref = $this->branch; |
|
58 | + } |
|
59 | + |
|
60 | + //Get headers from the main stylesheet in this branch/tag. Its "Version" header and other metadata |
|
61 | + //are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags. |
|
62 | + $remoteHeader = $this->getFileHeader($api->getRemoteFile('style.css', $ref)); |
|
63 | + $update->version = Puc_v4p4_Utils::findNotEmpty(array( |
|
64 | + $remoteHeader['Version'], |
|
65 | + Puc_v4p4_Utils::get($updateSource, 'version'), |
|
66 | + )); |
|
67 | + |
|
68 | + //The details URL defaults to the Theme URI header or the repository URL. |
|
69 | + $update->details_url = Puc_v4p4_Utils::findNotEmpty(array( |
|
70 | + $remoteHeader['ThemeURI'], |
|
71 | + $this->theme->get('ThemeURI'), |
|
72 | + $this->metadataUrl, |
|
73 | + )); |
|
74 | + |
|
75 | + if ( empty($update->version) ) { |
|
76 | + //It looks like we didn't find a valid update after all. |
|
77 | + $update = null; |
|
78 | + } |
|
79 | + |
|
80 | + $update = $this->filterUpdateResult($update); |
|
81 | + return $update; |
|
82 | + } |
|
83 | + |
|
84 | + //FIXME: This is duplicated code. Both theme and plugin subclasses that use VCS share these methods. |
|
85 | + |
|
86 | + public function setBranch($branch) { |
|
87 | + $this->branch = $branch; |
|
88 | + return $this; |
|
89 | + } |
|
90 | + |
|
91 | + public function setAuthentication($credentials) { |
|
92 | + $this->api->setAuthentication($credentials); |
|
93 | + return $this; |
|
94 | + } |
|
95 | + |
|
96 | + public function getVcsApi() { |
|
97 | + return $this->api; |
|
98 | + } |
|
99 | + |
|
100 | + public function getUpdate() { |
|
101 | + $update = parent::getUpdate(); |
|
102 | + |
|
103 | + if ( isset($update) && !empty($update->download_url) ) { |
|
104 | + $update->download_url = $this->api->signDownloadUrl($update->download_url); |
|
105 | + } |
|
106 | + |
|
107 | + return $update; |
|
108 | + } |
|
109 | + |
|
110 | + public function onDisplayConfiguration($panel) { |
|
111 | + parent::onDisplayConfiguration($panel); |
|
112 | + $panel->row('Branch', $this->branch); |
|
113 | + $panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No'); |
|
114 | + $panel->row('API client', get_class($this->api)); |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | 118 | endif; |
119 | 119 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( !class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false) ): |
|
3 | +if (!class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false)): |
|
4 | 4 | |
5 | 5 | class Puc_v4p4_Vcs_ThemeUpdateChecker extends Puc_v4p4_Theme_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker { |
6 | 6 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | //Figure out which reference (tag or branch) we'll use to get the latest version of the theme. |
42 | 42 | $updateSource = $api->chooseReference($this->branch); |
43 | - if ( $updateSource ) { |
|
43 | + if ($updateSource) { |
|
44 | 44 | $ref = $updateSource->name; |
45 | 45 | $update->download_url = $updateSource->downloadUrl; |
46 | 46 | } else { |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $this->metadataUrl, |
73 | 73 | )); |
74 | 74 | |
75 | - if ( empty($update->version) ) { |
|
75 | + if (empty($update->version)) { |
|
76 | 76 | //It looks like we didn't find a valid update after all. |
77 | 77 | $update = null; |
78 | 78 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | public function getUpdate() { |
101 | 101 | $update = parent::getUpdate(); |
102 | 102 | |
103 | - if ( isset($update) && !empty($update->download_url) ) { |
|
103 | + if (isset($update) && !empty($update->download_url)) { |
|
104 | 104 | $update->download_url = $this->api->signDownloadUrl($update->download_url); |
105 | 105 | } |
106 | 106 |
@@ -1,49 +1,49 @@ |
||
1 | 1 | <?php |
2 | 2 | if ( !class_exists('Puc_v4p4_Vcs_Reference', false) ): |
3 | 3 | |
4 | - /** |
|
5 | - * This class represents a VCS branch or tag. It's intended as a read only, short-lived container |
|
6 | - * that only exists to provide a limited degree of type checking. |
|
7 | - * |
|
8 | - * @property string $name |
|
9 | - * @property string|null version |
|
10 | - * @property string $downloadUrl |
|
11 | - * @property string $updated |
|
12 | - * |
|
13 | - * @property string|null $changelog |
|
14 | - * @property int|null $downloadCount |
|
15 | - */ |
|
16 | - class Puc_v4p4_Vcs_Reference { |
|
17 | - private $properties = array(); |
|
4 | + /** |
|
5 | + * This class represents a VCS branch or tag. It's intended as a read only, short-lived container |
|
6 | + * that only exists to provide a limited degree of type checking. |
|
7 | + * |
|
8 | + * @property string $name |
|
9 | + * @property string|null version |
|
10 | + * @property string $downloadUrl |
|
11 | + * @property string $updated |
|
12 | + * |
|
13 | + * @property string|null $changelog |
|
14 | + * @property int|null $downloadCount |
|
15 | + */ |
|
16 | + class Puc_v4p4_Vcs_Reference { |
|
17 | + private $properties = array(); |
|
18 | 18 | |
19 | - public function __construct($properties = array()) { |
|
20 | - $this->properties = $properties; |
|
21 | - } |
|
19 | + public function __construct($properties = array()) { |
|
20 | + $this->properties = $properties; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string $name |
|
25 | - * @return mixed|null |
|
26 | - */ |
|
27 | - public function __get($name) { |
|
28 | - return array_key_exists($name, $this->properties) ? $this->properties[$name] : null; |
|
29 | - } |
|
23 | + /** |
|
24 | + * @param string $name |
|
25 | + * @return mixed|null |
|
26 | + */ |
|
27 | + public function __get($name) { |
|
28 | + return array_key_exists($name, $this->properties) ? $this->properties[$name] : null; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param string $name |
|
33 | - * @param mixed $value |
|
34 | - */ |
|
35 | - public function __set($name, $value) { |
|
36 | - $this->properties[$name] = $value; |
|
37 | - } |
|
31 | + /** |
|
32 | + * @param string $name |
|
33 | + * @param mixed $value |
|
34 | + */ |
|
35 | + public function __set($name, $value) { |
|
36 | + $this->properties[$name] = $value; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $name |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function __isset($name) { |
|
44 | - return isset($this->properties[$name]); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @param string $name |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function __isset($name) { |
|
44 | + return isset($this->properties[$name]); |
|
45 | + } |
|
46 | 46 | |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | endif; |
50 | 50 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -if ( !class_exists('Puc_v4p4_Vcs_Reference', false) ): |
|
2 | +if (!class_exists('Puc_v4p4_Vcs_Reference', false)): |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * This class represents a VCS branch or tag. It's intended as a read only, short-lived container |
@@ -2,273 +2,273 @@ |
||
2 | 2 | |
3 | 3 | if ( !class_exists('Puc_v4p4_Vcs_GitLabApi', false) ): |
4 | 4 | |
5 | - class Puc_v4p4_Vcs_GitLabApi extends Puc_v4p4_Vcs_Api { |
|
6 | - /** |
|
7 | - * @var string GitLab username. |
|
8 | - */ |
|
9 | - protected $userName; |
|
10 | - |
|
11 | - /** |
|
12 | - * @var string GitLab server host. |
|
13 | - */ |
|
14 | - private $repositoryHost; |
|
15 | - |
|
16 | - /** |
|
17 | - * @var string GitLab repository name. |
|
18 | - */ |
|
19 | - protected $repositoryName; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var string GitLab authentication token. Optional. |
|
23 | - */ |
|
24 | - protected $accessToken; |
|
25 | - |
|
26 | - public function __construct($repositoryUrl, $accessToken = null) { |
|
27 | - //Parse the repository host to support custom hosts. |
|
28 | - $this->repositoryHost = @parse_url($repositoryUrl, PHP_URL_HOST); |
|
29 | - |
|
30 | - //Find the repository information |
|
31 | - $path = @parse_url($repositoryUrl, PHP_URL_PATH); |
|
32 | - if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) { |
|
33 | - $this->userName = $matches['username']; |
|
34 | - $this->repositoryName = $matches['repository']; |
|
35 | - } else { |
|
36 | - //This is not a traditional url, it could be gitlab is in a deeper subdirectory. |
|
37 | - //Get the path segments. |
|
38 | - $segments = explode('/', untrailingslashit(ltrim($path, '/'))); |
|
39 | - |
|
40 | - //We need at least /user-name/repository-name/ |
|
41 | - if ( count($segments) < 2 ) { |
|
42 | - throw new InvalidArgumentException('Invalid GitLab repository URL: "' . $repositoryUrl . '"'); |
|
43 | - } |
|
44 | - |
|
45 | - //Get the username and repository name. |
|
46 | - $usernameRepo = array_splice($segments, -2, 2); |
|
47 | - $this->userName = $usernameRepo[0]; |
|
48 | - $this->repositoryName = $usernameRepo[1]; |
|
49 | - |
|
50 | - //Append the remaining segments to the host. |
|
51 | - $this->repositoryHost = trailingslashit($this->repositoryHost) . implode('/', $segments); |
|
52 | - } |
|
53 | - |
|
54 | - parent::__construct($repositoryUrl, $accessToken); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Get the latest release from GitLab. |
|
59 | - * |
|
60 | - * @return Puc_v4p4_Vcs_Reference|null |
|
61 | - */ |
|
62 | - public function getLatestRelease() { |
|
63 | - return $this->getLatestTag(); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Get the tag that looks like the highest version number. |
|
68 | - * |
|
69 | - * @return Puc_v4p4_Vcs_Reference|null |
|
70 | - */ |
|
71 | - public function getLatestTag() { |
|
72 | - $tags = $this->api('/:user/:repo/repository/tags'); |
|
73 | - if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) { |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - $versionTags = $this->sortTagsByVersion($tags); |
|
78 | - if ( empty($versionTags) ) { |
|
79 | - return null; |
|
80 | - } |
|
81 | - |
|
82 | - $tag = $versionTags[0]; |
|
83 | - return new Puc_v4p4_Vcs_Reference(array( |
|
84 | - 'name' => $tag->name, |
|
85 | - 'version' => ltrim($tag->name, 'v'), |
|
86 | - 'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name), |
|
87 | - 'apiResponse' => $tag |
|
88 | - )); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Get a branch by name. |
|
93 | - * |
|
94 | - * @param string $branchName |
|
95 | - * @return null|Puc_v4p4_Vcs_Reference |
|
96 | - */ |
|
97 | - public function getBranch($branchName) { |
|
98 | - $branch = $this->api('/:user/:repo/repository/branches/' . $branchName); |
|
99 | - if ( is_wp_error($branch) || empty($branch) ) { |
|
100 | - return null; |
|
101 | - } |
|
102 | - |
|
103 | - $reference = new Puc_v4p4_Vcs_Reference(array( |
|
104 | - 'name' => $branch->name, |
|
105 | - 'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name), |
|
106 | - 'apiResponse' => $branch, |
|
107 | - )); |
|
108 | - |
|
109 | - if ( isset($branch->commit, $branch->commit->committed_date) ) { |
|
110 | - $reference->updated = $branch->commit->committed_date; |
|
111 | - } |
|
112 | - |
|
113 | - return $reference; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get the timestamp of the latest commit that changed the specified branch or tag. |
|
118 | - * |
|
119 | - * @param string $ref Reference name (e.g. branch or tag). |
|
120 | - * @return string|null |
|
121 | - */ |
|
122 | - public function getLatestCommitTime($ref) { |
|
123 | - $commits = $this->api('/:user/:repo/repository/commits/', array('ref_name' => $ref)); |
|
124 | - if ( is_wp_error($commits) || !is_array($commits) || !isset($commits[0]) ) { |
|
125 | - return null; |
|
126 | - } |
|
127 | - |
|
128 | - return $commits[0]->committed_date; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Perform a GitLab API request. |
|
133 | - * |
|
134 | - * @param string $url |
|
135 | - * @param array $queryParams |
|
136 | - * @return mixed|WP_Error |
|
137 | - */ |
|
138 | - protected function api($url, $queryParams = array()) { |
|
139 | - $baseUrl = $url; |
|
140 | - $url = $this->buildApiUrl($url, $queryParams); |
|
141 | - |
|
142 | - $options = array('timeout' => 10); |
|
143 | - if ( !empty($this->httpFilterName) ) { |
|
144 | - $options = apply_filters($this->httpFilterName, $options); |
|
145 | - } |
|
5 | + class Puc_v4p4_Vcs_GitLabApi extends Puc_v4p4_Vcs_Api { |
|
6 | + /** |
|
7 | + * @var string GitLab username. |
|
8 | + */ |
|
9 | + protected $userName; |
|
10 | + |
|
11 | + /** |
|
12 | + * @var string GitLab server host. |
|
13 | + */ |
|
14 | + private $repositoryHost; |
|
15 | + |
|
16 | + /** |
|
17 | + * @var string GitLab repository name. |
|
18 | + */ |
|
19 | + protected $repositoryName; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var string GitLab authentication token. Optional. |
|
23 | + */ |
|
24 | + protected $accessToken; |
|
25 | + |
|
26 | + public function __construct($repositoryUrl, $accessToken = null) { |
|
27 | + //Parse the repository host to support custom hosts. |
|
28 | + $this->repositoryHost = @parse_url($repositoryUrl, PHP_URL_HOST); |
|
29 | + |
|
30 | + //Find the repository information |
|
31 | + $path = @parse_url($repositoryUrl, PHP_URL_PATH); |
|
32 | + if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) { |
|
33 | + $this->userName = $matches['username']; |
|
34 | + $this->repositoryName = $matches['repository']; |
|
35 | + } else { |
|
36 | + //This is not a traditional url, it could be gitlab is in a deeper subdirectory. |
|
37 | + //Get the path segments. |
|
38 | + $segments = explode('/', untrailingslashit(ltrim($path, '/'))); |
|
39 | + |
|
40 | + //We need at least /user-name/repository-name/ |
|
41 | + if ( count($segments) < 2 ) { |
|
42 | + throw new InvalidArgumentException('Invalid GitLab repository URL: "' . $repositoryUrl . '"'); |
|
43 | + } |
|
44 | + |
|
45 | + //Get the username and repository name. |
|
46 | + $usernameRepo = array_splice($segments, -2, 2); |
|
47 | + $this->userName = $usernameRepo[0]; |
|
48 | + $this->repositoryName = $usernameRepo[1]; |
|
49 | + |
|
50 | + //Append the remaining segments to the host. |
|
51 | + $this->repositoryHost = trailingslashit($this->repositoryHost) . implode('/', $segments); |
|
52 | + } |
|
53 | + |
|
54 | + parent::__construct($repositoryUrl, $accessToken); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Get the latest release from GitLab. |
|
59 | + * |
|
60 | + * @return Puc_v4p4_Vcs_Reference|null |
|
61 | + */ |
|
62 | + public function getLatestRelease() { |
|
63 | + return $this->getLatestTag(); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Get the tag that looks like the highest version number. |
|
68 | + * |
|
69 | + * @return Puc_v4p4_Vcs_Reference|null |
|
70 | + */ |
|
71 | + public function getLatestTag() { |
|
72 | + $tags = $this->api('/:user/:repo/repository/tags'); |
|
73 | + if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) { |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + $versionTags = $this->sortTagsByVersion($tags); |
|
78 | + if ( empty($versionTags) ) { |
|
79 | + return null; |
|
80 | + } |
|
81 | + |
|
82 | + $tag = $versionTags[0]; |
|
83 | + return new Puc_v4p4_Vcs_Reference(array( |
|
84 | + 'name' => $tag->name, |
|
85 | + 'version' => ltrim($tag->name, 'v'), |
|
86 | + 'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name), |
|
87 | + 'apiResponse' => $tag |
|
88 | + )); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Get a branch by name. |
|
93 | + * |
|
94 | + * @param string $branchName |
|
95 | + * @return null|Puc_v4p4_Vcs_Reference |
|
96 | + */ |
|
97 | + public function getBranch($branchName) { |
|
98 | + $branch = $this->api('/:user/:repo/repository/branches/' . $branchName); |
|
99 | + if ( is_wp_error($branch) || empty($branch) ) { |
|
100 | + return null; |
|
101 | + } |
|
102 | + |
|
103 | + $reference = new Puc_v4p4_Vcs_Reference(array( |
|
104 | + 'name' => $branch->name, |
|
105 | + 'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name), |
|
106 | + 'apiResponse' => $branch, |
|
107 | + )); |
|
108 | + |
|
109 | + if ( isset($branch->commit, $branch->commit->committed_date) ) { |
|
110 | + $reference->updated = $branch->commit->committed_date; |
|
111 | + } |
|
112 | + |
|
113 | + return $reference; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get the timestamp of the latest commit that changed the specified branch or tag. |
|
118 | + * |
|
119 | + * @param string $ref Reference name (e.g. branch or tag). |
|
120 | + * @return string|null |
|
121 | + */ |
|
122 | + public function getLatestCommitTime($ref) { |
|
123 | + $commits = $this->api('/:user/:repo/repository/commits/', array('ref_name' => $ref)); |
|
124 | + if ( is_wp_error($commits) || !is_array($commits) || !isset($commits[0]) ) { |
|
125 | + return null; |
|
126 | + } |
|
127 | + |
|
128 | + return $commits[0]->committed_date; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Perform a GitLab API request. |
|
133 | + * |
|
134 | + * @param string $url |
|
135 | + * @param array $queryParams |
|
136 | + * @return mixed|WP_Error |
|
137 | + */ |
|
138 | + protected function api($url, $queryParams = array()) { |
|
139 | + $baseUrl = $url; |
|
140 | + $url = $this->buildApiUrl($url, $queryParams); |
|
141 | + |
|
142 | + $options = array('timeout' => 10); |
|
143 | + if ( !empty($this->httpFilterName) ) { |
|
144 | + $options = apply_filters($this->httpFilterName, $options); |
|
145 | + } |
|
146 | 146 | |
147 | - $response = wp_remote_get($url, $options); |
|
148 | - if ( is_wp_error($response) ) { |
|
149 | - do_action('puc_api_error', $response, null, $url, $this->slug); |
|
150 | - return $response; |
|
151 | - } |
|
152 | - |
|
153 | - $code = wp_remote_retrieve_response_code($response); |
|
154 | - $body = wp_remote_retrieve_body($response); |
|
155 | - if ( $code === 200 ) { |
|
156 | - return json_decode($body); |
|
157 | - } |
|
158 | - |
|
159 | - $error = new WP_Error( |
|
160 | - 'puc-gitlab-http-error', |
|
161 | - sprintf('GitLab API error. URL: "%s", HTTP status code: %d.', $baseUrl, $code) |
|
162 | - ); |
|
163 | - do_action('puc_api_error', $error, $response, $url, $this->slug); |
|
164 | - |
|
165 | - return $error; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Build a fully qualified URL for an API request. |
|
170 | - * |
|
171 | - * @param string $url |
|
172 | - * @param array $queryParams |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - protected function buildApiUrl($url, $queryParams) { |
|
176 | - $variables = array( |
|
177 | - 'user' => $this->userName, |
|
178 | - 'repo' => $this->repositoryName |
|
179 | - ); |
|
180 | - |
|
181 | - foreach ($variables as $name => $value) { |
|
182 | - $url = str_replace("/:{$name}", urlencode('/' . $value), $url); |
|
183 | - } |
|
184 | - |
|
185 | - $url = substr($url, 3); |
|
186 | - $url = sprintf('https://%1$s/api/v4/projects/%2$s', $this->repositoryHost, $url); |
|
187 | - |
|
188 | - if ( !empty($this->accessToken) ) { |
|
189 | - $queryParams['private_token'] = $this->accessToken; |
|
190 | - } |
|
191 | - |
|
192 | - if ( !empty($queryParams) ) { |
|
193 | - $url = add_query_arg($queryParams, $url); |
|
194 | - } |
|
195 | - |
|
196 | - return $url; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Get the contents of a file from a specific branch or tag. |
|
201 | - * |
|
202 | - * @param string $path File name. |
|
203 | - * @param string $ref |
|
204 | - * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error. |
|
205 | - */ |
|
206 | - public function getRemoteFile($path, $ref = 'master') { |
|
207 | - $response = $this->api('/:user/:repo/repository/files/' . $path, array('ref' => $ref)); |
|
208 | - if ( is_wp_error($response) || !isset($response->content) || $response->encoding !== 'base64' ) { |
|
209 | - return null; |
|
210 | - } |
|
211 | - |
|
212 | - return base64_decode($response->content); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Generate a URL to download a ZIP archive of the specified branch/tag/etc. |
|
217 | - * |
|
218 | - * @param string $ref |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - public function buildArchiveDownloadUrl($ref = 'master') { |
|
222 | - $url = sprintf( |
|
223 | - 'https://%1$s/%2$s/%3$s/repository/%4$s/archive.zip', |
|
224 | - $this->repositoryHost, |
|
225 | - urlencode($this->userName), |
|
226 | - urlencode($this->repositoryName), |
|
227 | - urlencode($ref) |
|
228 | - ); |
|
229 | - |
|
230 | - if ( !empty($this->accessToken) ) { |
|
231 | - $url = add_query_arg('private_token', $this->accessToken, $url); |
|
232 | - } |
|
233 | - |
|
234 | - return $url; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Get a specific tag. |
|
239 | - * |
|
240 | - * @param string $tagName |
|
241 | - * @return Puc_v4p4_Vcs_Reference|null |
|
242 | - */ |
|
243 | - public function getTag($tagName) { |
|
244 | - throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.'); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Figure out which reference (i.e tag or branch) contains the latest version. |
|
249 | - * |
|
250 | - * @param string $configBranch Start looking in this branch. |
|
251 | - * @return null|Puc_v4p4_Vcs_Reference |
|
252 | - */ |
|
253 | - public function chooseReference($configBranch) { |
|
254 | - $updateSource = null; |
|
255 | - |
|
256 | - // GitLab doesn't handle releases the same as GitHub so just use the latest tag |
|
257 | - if ( $configBranch === 'master' ) { |
|
258 | - $updateSource = $this->getLatestTag(); |
|
259 | - } |
|
260 | - |
|
261 | - if ( empty($updateSource) ) { |
|
262 | - $updateSource = $this->getBranch($configBranch); |
|
263 | - } |
|
264 | - |
|
265 | - return $updateSource; |
|
266 | - } |
|
267 | - |
|
268 | - public function setAuthentication($credentials) { |
|
269 | - parent::setAuthentication($credentials); |
|
270 | - $this->accessToken = is_string($credentials) ? $credentials : null; |
|
271 | - } |
|
272 | - } |
|
147 | + $response = wp_remote_get($url, $options); |
|
148 | + if ( is_wp_error($response) ) { |
|
149 | + do_action('puc_api_error', $response, null, $url, $this->slug); |
|
150 | + return $response; |
|
151 | + } |
|
152 | + |
|
153 | + $code = wp_remote_retrieve_response_code($response); |
|
154 | + $body = wp_remote_retrieve_body($response); |
|
155 | + if ( $code === 200 ) { |
|
156 | + return json_decode($body); |
|
157 | + } |
|
158 | + |
|
159 | + $error = new WP_Error( |
|
160 | + 'puc-gitlab-http-error', |
|
161 | + sprintf('GitLab API error. URL: "%s", HTTP status code: %d.', $baseUrl, $code) |
|
162 | + ); |
|
163 | + do_action('puc_api_error', $error, $response, $url, $this->slug); |
|
164 | + |
|
165 | + return $error; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Build a fully qualified URL for an API request. |
|
170 | + * |
|
171 | + * @param string $url |
|
172 | + * @param array $queryParams |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + protected function buildApiUrl($url, $queryParams) { |
|
176 | + $variables = array( |
|
177 | + 'user' => $this->userName, |
|
178 | + 'repo' => $this->repositoryName |
|
179 | + ); |
|
180 | + |
|
181 | + foreach ($variables as $name => $value) { |
|
182 | + $url = str_replace("/:{$name}", urlencode('/' . $value), $url); |
|
183 | + } |
|
184 | + |
|
185 | + $url = substr($url, 3); |
|
186 | + $url = sprintf('https://%1$s/api/v4/projects/%2$s', $this->repositoryHost, $url); |
|
187 | + |
|
188 | + if ( !empty($this->accessToken) ) { |
|
189 | + $queryParams['private_token'] = $this->accessToken; |
|
190 | + } |
|
191 | + |
|
192 | + if ( !empty($queryParams) ) { |
|
193 | + $url = add_query_arg($queryParams, $url); |
|
194 | + } |
|
195 | + |
|
196 | + return $url; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Get the contents of a file from a specific branch or tag. |
|
201 | + * |
|
202 | + * @param string $path File name. |
|
203 | + * @param string $ref |
|
204 | + * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error. |
|
205 | + */ |
|
206 | + public function getRemoteFile($path, $ref = 'master') { |
|
207 | + $response = $this->api('/:user/:repo/repository/files/' . $path, array('ref' => $ref)); |
|
208 | + if ( is_wp_error($response) || !isset($response->content) || $response->encoding !== 'base64' ) { |
|
209 | + return null; |
|
210 | + } |
|
211 | + |
|
212 | + return base64_decode($response->content); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Generate a URL to download a ZIP archive of the specified branch/tag/etc. |
|
217 | + * |
|
218 | + * @param string $ref |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + public function buildArchiveDownloadUrl($ref = 'master') { |
|
222 | + $url = sprintf( |
|
223 | + 'https://%1$s/%2$s/%3$s/repository/%4$s/archive.zip', |
|
224 | + $this->repositoryHost, |
|
225 | + urlencode($this->userName), |
|
226 | + urlencode($this->repositoryName), |
|
227 | + urlencode($ref) |
|
228 | + ); |
|
229 | + |
|
230 | + if ( !empty($this->accessToken) ) { |
|
231 | + $url = add_query_arg('private_token', $this->accessToken, $url); |
|
232 | + } |
|
233 | + |
|
234 | + return $url; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Get a specific tag. |
|
239 | + * |
|
240 | + * @param string $tagName |
|
241 | + * @return Puc_v4p4_Vcs_Reference|null |
|
242 | + */ |
|
243 | + public function getTag($tagName) { |
|
244 | + throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.'); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Figure out which reference (i.e tag or branch) contains the latest version. |
|
249 | + * |
|
250 | + * @param string $configBranch Start looking in this branch. |
|
251 | + * @return null|Puc_v4p4_Vcs_Reference |
|
252 | + */ |
|
253 | + public function chooseReference($configBranch) { |
|
254 | + $updateSource = null; |
|
255 | + |
|
256 | + // GitLab doesn't handle releases the same as GitHub so just use the latest tag |
|
257 | + if ( $configBranch === 'master' ) { |
|
258 | + $updateSource = $this->getLatestTag(); |
|
259 | + } |
|
260 | + |
|
261 | + if ( empty($updateSource) ) { |
|
262 | + $updateSource = $this->getBranch($configBranch); |
|
263 | + } |
|
264 | + |
|
265 | + return $updateSource; |
|
266 | + } |
|
267 | + |
|
268 | + public function setAuthentication($credentials) { |
|
269 | + parent::setAuthentication($credentials); |
|
270 | + $this->accessToken = is_string($credentials) ? $credentials : null; |
|
271 | + } |
|
272 | + } |
|
273 | 273 | |
274 | 274 | endif; |
275 | 275 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( !class_exists('Puc_v4p4_Vcs_GitLabApi', false) ): |
|
3 | +if (!class_exists('Puc_v4p4_Vcs_GitLabApi', false)): |
|
4 | 4 | |
5 | 5 | class Puc_v4p4_Vcs_GitLabApi extends Puc_v4p4_Vcs_Api { |
6 | 6 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | //Find the repository information |
31 | 31 | $path = @parse_url($repositoryUrl, PHP_URL_PATH); |
32 | - if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) { |
|
32 | + if (preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches)) { |
|
33 | 33 | $this->userName = $matches['username']; |
34 | 34 | $this->repositoryName = $matches['repository']; |
35 | 35 | } else { |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | $segments = explode('/', untrailingslashit(ltrim($path, '/'))); |
39 | 39 | |
40 | 40 | //We need at least /user-name/repository-name/ |
41 | - if ( count($segments) < 2 ) { |
|
42 | - throw new InvalidArgumentException('Invalid GitLab repository URL: "' . $repositoryUrl . '"'); |
|
41 | + if (count($segments) < 2) { |
|
42 | + throw new InvalidArgumentException('Invalid GitLab repository URL: "'.$repositoryUrl.'"'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | //Get the username and repository name. |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $this->repositoryName = $usernameRepo[1]; |
49 | 49 | |
50 | 50 | //Append the remaining segments to the host. |
51 | - $this->repositoryHost = trailingslashit($this->repositoryHost) . implode('/', $segments); |
|
51 | + $this->repositoryHost = trailingslashit($this->repositoryHost).implode('/', $segments); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | parent::__construct($repositoryUrl, $accessToken); |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function getLatestTag() { |
72 | 72 | $tags = $this->api('/:user/:repo/repository/tags'); |
73 | - if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) { |
|
73 | + if (is_wp_error($tags) || empty($tags) || !is_array($tags)) { |
|
74 | 74 | return null; |
75 | 75 | } |
76 | 76 | |
77 | 77 | $versionTags = $this->sortTagsByVersion($tags); |
78 | - if ( empty($versionTags) ) { |
|
78 | + if (empty($versionTags)) { |
|
79 | 79 | return null; |
80 | 80 | } |
81 | 81 | |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | * @return null|Puc_v4p4_Vcs_Reference |
96 | 96 | */ |
97 | 97 | public function getBranch($branchName) { |
98 | - $branch = $this->api('/:user/:repo/repository/branches/' . $branchName); |
|
99 | - if ( is_wp_error($branch) || empty($branch) ) { |
|
98 | + $branch = $this->api('/:user/:repo/repository/branches/'.$branchName); |
|
99 | + if (is_wp_error($branch) || empty($branch)) { |
|
100 | 100 | return null; |
101 | 101 | } |
102 | 102 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | 'apiResponse' => $branch, |
107 | 107 | )); |
108 | 108 | |
109 | - if ( isset($branch->commit, $branch->commit->committed_date) ) { |
|
109 | + if (isset($branch->commit, $branch->commit->committed_date)) { |
|
110 | 110 | $reference->updated = $branch->commit->committed_date; |
111 | 111 | } |
112 | 112 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function getLatestCommitTime($ref) { |
123 | 123 | $commits = $this->api('/:user/:repo/repository/commits/', array('ref_name' => $ref)); |
124 | - if ( is_wp_error($commits) || !is_array($commits) || !isset($commits[0]) ) { |
|
124 | + if (is_wp_error($commits) || !is_array($commits) || !isset($commits[0])) { |
|
125 | 125 | return null; |
126 | 126 | } |
127 | 127 | |
@@ -140,19 +140,19 @@ discard block |
||
140 | 140 | $url = $this->buildApiUrl($url, $queryParams); |
141 | 141 | |
142 | 142 | $options = array('timeout' => 10); |
143 | - if ( !empty($this->httpFilterName) ) { |
|
143 | + if (!empty($this->httpFilterName)) { |
|
144 | 144 | $options = apply_filters($this->httpFilterName, $options); |
145 | 145 | } |
146 | 146 | |
147 | 147 | $response = wp_remote_get($url, $options); |
148 | - if ( is_wp_error($response) ) { |
|
148 | + if (is_wp_error($response)) { |
|
149 | 149 | do_action('puc_api_error', $response, null, $url, $this->slug); |
150 | 150 | return $response; |
151 | 151 | } |
152 | 152 | |
153 | 153 | $code = wp_remote_retrieve_response_code($response); |
154 | 154 | $body = wp_remote_retrieve_body($response); |
155 | - if ( $code === 200 ) { |
|
155 | + if ($code === 200) { |
|
156 | 156 | return json_decode($body); |
157 | 157 | } |
158 | 158 | |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | ); |
180 | 180 | |
181 | 181 | foreach ($variables as $name => $value) { |
182 | - $url = str_replace("/:{$name}", urlencode('/' . $value), $url); |
|
182 | + $url = str_replace("/:{$name}", urlencode('/'.$value), $url); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | $url = substr($url, 3); |
186 | 186 | $url = sprintf('https://%1$s/api/v4/projects/%2$s', $this->repositoryHost, $url); |
187 | 187 | |
188 | - if ( !empty($this->accessToken) ) { |
|
188 | + if (!empty($this->accessToken)) { |
|
189 | 189 | $queryParams['private_token'] = $this->accessToken; |
190 | 190 | } |
191 | 191 | |
192 | - if ( !empty($queryParams) ) { |
|
192 | + if (!empty($queryParams)) { |
|
193 | 193 | $url = add_query_arg($queryParams, $url); |
194 | 194 | } |
195 | 195 | |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error. |
205 | 205 | */ |
206 | 206 | public function getRemoteFile($path, $ref = 'master') { |
207 | - $response = $this->api('/:user/:repo/repository/files/' . $path, array('ref' => $ref)); |
|
208 | - if ( is_wp_error($response) || !isset($response->content) || $response->encoding !== 'base64' ) { |
|
207 | + $response = $this->api('/:user/:repo/repository/files/'.$path, array('ref' => $ref)); |
|
208 | + if (is_wp_error($response) || !isset($response->content) || $response->encoding !== 'base64') { |
|
209 | 209 | return null; |
210 | 210 | } |
211 | 211 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | urlencode($ref) |
228 | 228 | ); |
229 | 229 | |
230 | - if ( !empty($this->accessToken) ) { |
|
230 | + if (!empty($this->accessToken)) { |
|
231 | 231 | $url = add_query_arg('private_token', $this->accessToken, $url); |
232 | 232 | } |
233 | 233 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @return Puc_v4p4_Vcs_Reference|null |
242 | 242 | */ |
243 | 243 | public function getTag($tagName) { |
244 | - throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.'); |
|
244 | + throw new LogicException('The '.__METHOD__.' method is not implemented and should not be used.'); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | $updateSource = null; |
255 | 255 | |
256 | 256 | // GitLab doesn't handle releases the same as GitHub so just use the latest tag |
257 | - if ( $configBranch === 'master' ) { |
|
257 | + if ($configBranch === 'master') { |
|
258 | 258 | $updateSource = $this->getLatestTag(); |
259 | 259 | } |
260 | 260 | |
261 | - if ( empty($updateSource) ) { |
|
261 | + if (empty($updateSource)) { |
|
262 | 262 | $updateSource = $this->getBranch($configBranch); |
263 | 263 | } |
264 | 264 |
@@ -1,302 +1,302 @@ |
||
1 | 1 | <?php |
2 | 2 | if ( !class_exists('Puc_v4p4_Vcs_Api') ): |
3 | 3 | |
4 | - abstract class Puc_v4p4_Vcs_Api { |
|
5 | - protected $tagNameProperty = 'name'; |
|
6 | - protected $slug = ''; |
|
7 | - |
|
8 | - /** |
|
9 | - * @var string |
|
10 | - */ |
|
11 | - protected $repositoryUrl = ''; |
|
12 | - |
|
13 | - /** |
|
14 | - * @var mixed Authentication details for private repositories. Format depends on service. |
|
15 | - */ |
|
16 | - protected $credentials = null; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var string The filter tag that's used to filter options passed to wp_remote_get. |
|
20 | - * For example, "puc_request_info_options-slug" or "puc_request_update_options_theme-slug". |
|
21 | - */ |
|
22 | - protected $httpFilterName = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string|null |
|
26 | - */ |
|
27 | - protected $localDirectory = null; |
|
28 | - |
|
29 | - /** |
|
30 | - * Puc_v4p4_Vcs_Api constructor. |
|
31 | - * |
|
32 | - * @param string $repositoryUrl |
|
33 | - * @param array|string|null $credentials |
|
34 | - */ |
|
35 | - public function __construct($repositoryUrl, $credentials = null) { |
|
36 | - $this->repositoryUrl = $repositoryUrl; |
|
37 | - $this->setAuthentication($credentials); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function getRepositoryUrl() { |
|
44 | - return $this->repositoryUrl; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Figure out which reference (i.e tag or branch) contains the latest version. |
|
49 | - * |
|
50 | - * @param string $configBranch Start looking in this branch. |
|
51 | - * @return null|Puc_v4p4_Vcs_Reference |
|
52 | - */ |
|
53 | - abstract public function chooseReference($configBranch); |
|
54 | - |
|
55 | - /** |
|
56 | - * Get the readme.txt file from the remote repository and parse it |
|
57 | - * according to the plugin readme standard. |
|
58 | - * |
|
59 | - * @param string $ref Tag or branch name. |
|
60 | - * @return array Parsed readme. |
|
61 | - */ |
|
62 | - public function getRemoteReadme($ref = 'master') { |
|
63 | - $fileContents = $this->getRemoteFile($this->getLocalReadmeName(), $ref); |
|
64 | - if ( empty($fileContents) ) { |
|
65 | - return array(); |
|
66 | - } |
|
67 | - |
|
68 | - $parser = new PucReadmeParser(); |
|
69 | - return $parser->parse_readme_contents($fileContents); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get the case-sensitive name of the local readme.txt file. |
|
74 | - * |
|
75 | - * In most cases it should just be called "readme.txt", but some plugins call it "README.txt", |
|
76 | - * "README.TXT", or even "Readme.txt". Most VCS are case-sensitive so we need to know the correct |
|
77 | - * capitalization. |
|
78 | - * |
|
79 | - * Defaults to "readme.txt" (all lowercase). |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getLocalReadmeName() { |
|
84 | - static $fileName = null; |
|
85 | - if ( $fileName !== null ) { |
|
86 | - return $fileName; |
|
87 | - } |
|
88 | - |
|
89 | - $fileName = 'readme.txt'; |
|
90 | - if ( isset($this->localDirectory) ) { |
|
91 | - $files = scandir($this->localDirectory); |
|
92 | - if ( !empty($files) ) { |
|
93 | - foreach ($files as $possibleFileName) { |
|
94 | - if ( strcasecmp($possibleFileName, 'readme.txt') === 0 ) { |
|
95 | - $fileName = $possibleFileName; |
|
96 | - break; |
|
97 | - } |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - return $fileName; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Get a branch. |
|
106 | - * |
|
107 | - * @param string $branchName |
|
108 | - * @return Puc_v4p4_Vcs_Reference|null |
|
109 | - */ |
|
110 | - abstract public function getBranch($branchName); |
|
111 | - |
|
112 | - /** |
|
113 | - * Get a specific tag. |
|
114 | - * |
|
115 | - * @param string $tagName |
|
116 | - * @return Puc_v4p4_Vcs_Reference|null |
|
117 | - */ |
|
118 | - abstract public function getTag($tagName); |
|
119 | - |
|
120 | - /** |
|
121 | - * Get the tag that looks like the highest version number. |
|
122 | - * (Implementations should skip pre-release versions if possible.) |
|
123 | - * |
|
124 | - * @return Puc_v4p4_Vcs_Reference|null |
|
125 | - */ |
|
126 | - abstract public function getLatestTag(); |
|
127 | - |
|
128 | - /** |
|
129 | - * Check if a tag name string looks like a version number. |
|
130 | - * |
|
131 | - * @param string $name |
|
132 | - * @return bool |
|
133 | - */ |
|
134 | - protected function looksLikeVersion($name) { |
|
135 | - //Tag names may be prefixed with "v", e.g. "v1.2.3". |
|
136 | - $name = ltrim($name, 'v'); |
|
137 | - |
|
138 | - //The version string must start with a number. |
|
139 | - if ( !is_numeric(substr($name, 0, 1)) ) { |
|
140 | - return false; |
|
141 | - } |
|
142 | - |
|
143 | - //The goal is to accept any SemVer-compatible or "PHP-standardized" version number. |
|
144 | - return (preg_match('@^(\d{1,5}?)(\.\d{1,10}?){0,4}?($|[abrdp+_\-]|\s)@i', $name) === 1); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Check if a tag appears to be named like a version number. |
|
149 | - * |
|
150 | - * @param stdClass $tag |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - protected function isVersionTag($tag) { |
|
154 | - $property = $this->tagNameProperty; |
|
155 | - return isset($tag->$property) && $this->looksLikeVersion($tag->$property); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Sort a list of tags as if they were version numbers. |
|
160 | - * Tags that don't look like version number will be removed. |
|
161 | - * |
|
162 | - * @param stdClass[] $tags Array of tag objects. |
|
163 | - * @return stdClass[] Filtered array of tags sorted in descending order. |
|
164 | - */ |
|
165 | - protected function sortTagsByVersion($tags) { |
|
166 | - //Keep only those tags that look like version numbers. |
|
167 | - $versionTags = array_filter($tags, array($this, 'isVersionTag')); |
|
168 | - //Sort them in descending order. |
|
169 | - usort($versionTags, array($this, 'compareTagNames')); |
|
170 | - |
|
171 | - return $versionTags; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Compare two tags as if they were version number. |
|
176 | - * |
|
177 | - * @param stdClass $tag1 Tag object. |
|
178 | - * @param stdClass $tag2 Another tag object. |
|
179 | - * @return int |
|
180 | - */ |
|
181 | - protected function compareTagNames($tag1, $tag2) { |
|
182 | - $property = $this->tagNameProperty; |
|
183 | - if ( !isset($tag1->$property) ) { |
|
184 | - return 1; |
|
185 | - } |
|
186 | - if ( !isset($tag2->$property) ) { |
|
187 | - return -1; |
|
188 | - } |
|
189 | - return -version_compare(ltrim($tag1->$property, 'v'), ltrim($tag2->$property, 'v')); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Get the contents of a file from a specific branch or tag. |
|
194 | - * |
|
195 | - * @param string $path File name. |
|
196 | - * @param string $ref |
|
197 | - * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error. |
|
198 | - */ |
|
199 | - abstract public function getRemoteFile($path, $ref = 'master'); |
|
200 | - |
|
201 | - /** |
|
202 | - * Get the timestamp of the latest commit that changed the specified branch or tag. |
|
203 | - * |
|
204 | - * @param string $ref Reference name (e.g. branch or tag). |
|
205 | - * @return string|null |
|
206 | - */ |
|
207 | - abstract public function getLatestCommitTime($ref); |
|
208 | - |
|
209 | - /** |
|
210 | - * Get the contents of the changelog file from the repository. |
|
211 | - * |
|
212 | - * @param string $ref |
|
213 | - * @param string $localDirectory Full path to the local plugin or theme directory. |
|
214 | - * @return null|string The HTML contents of the changelog. |
|
215 | - */ |
|
216 | - public function getRemoteChangelog($ref, $localDirectory) { |
|
217 | - $filename = $this->findChangelogName($localDirectory); |
|
218 | - if ( empty($filename) ) { |
|
219 | - return null; |
|
220 | - } |
|
221 | - |
|
222 | - $changelog = $this->getRemoteFile($filename, $ref); |
|
223 | - if ( $changelog === null ) { |
|
224 | - return null; |
|
225 | - } |
|
226 | - |
|
227 | - /** @noinspection PhpUndefinedClassInspection */ |
|
228 | - return Parsedown::instance()->text($changelog); |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Guess the name of the changelog file. |
|
233 | - * |
|
234 | - * @param string $directory |
|
235 | - * @return string|null |
|
236 | - */ |
|
237 | - protected function findChangelogName($directory = null) { |
|
238 | - if ( !isset($directory) ) { |
|
239 | - $directory = $this->localDirectory; |
|
240 | - } |
|
241 | - if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) { |
|
242 | - return null; |
|
243 | - } |
|
244 | - |
|
245 | - $possibleNames = array('CHANGES.md', 'CHANGELOG.md', 'changes.md', 'changelog.md'); |
|
246 | - $files = scandir($directory); |
|
247 | - $foundNames = array_intersect($possibleNames, $files); |
|
248 | - |
|
249 | - if ( !empty($foundNames) ) { |
|
250 | - return reset($foundNames); |
|
251 | - } |
|
252 | - return null; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Set authentication credentials. |
|
257 | - * |
|
258 | - * @param $credentials |
|
259 | - */ |
|
260 | - public function setAuthentication($credentials) { |
|
261 | - $this->credentials = $credentials; |
|
262 | - } |
|
263 | - |
|
264 | - public function isAuthenticationEnabled() { |
|
265 | - return !empty($this->credentials); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @param string $url |
|
270 | - * @return string |
|
271 | - */ |
|
272 | - public function signDownloadUrl($url) { |
|
273 | - return $url; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @param string $filterName |
|
278 | - */ |
|
279 | - public function setHttpFilterName($filterName) { |
|
280 | - $this->httpFilterName = $filterName; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * @param string $directory |
|
285 | - */ |
|
286 | - public function setLocalDirectory($directory) { |
|
287 | - if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) { |
|
288 | - $this->localDirectory = null; |
|
289 | - } else { |
|
290 | - $this->localDirectory = $directory; |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * @param string $slug |
|
296 | - */ |
|
297 | - public function setSlug($slug) { |
|
298 | - $this->slug = $slug; |
|
299 | - } |
|
300 | - } |
|
4 | + abstract class Puc_v4p4_Vcs_Api { |
|
5 | + protected $tagNameProperty = 'name'; |
|
6 | + protected $slug = ''; |
|
7 | + |
|
8 | + /** |
|
9 | + * @var string |
|
10 | + */ |
|
11 | + protected $repositoryUrl = ''; |
|
12 | + |
|
13 | + /** |
|
14 | + * @var mixed Authentication details for private repositories. Format depends on service. |
|
15 | + */ |
|
16 | + protected $credentials = null; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var string The filter tag that's used to filter options passed to wp_remote_get. |
|
20 | + * For example, "puc_request_info_options-slug" or "puc_request_update_options_theme-slug". |
|
21 | + */ |
|
22 | + protected $httpFilterName = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string|null |
|
26 | + */ |
|
27 | + protected $localDirectory = null; |
|
28 | + |
|
29 | + /** |
|
30 | + * Puc_v4p4_Vcs_Api constructor. |
|
31 | + * |
|
32 | + * @param string $repositoryUrl |
|
33 | + * @param array|string|null $credentials |
|
34 | + */ |
|
35 | + public function __construct($repositoryUrl, $credentials = null) { |
|
36 | + $this->repositoryUrl = $repositoryUrl; |
|
37 | + $this->setAuthentication($credentials); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function getRepositoryUrl() { |
|
44 | + return $this->repositoryUrl; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Figure out which reference (i.e tag or branch) contains the latest version. |
|
49 | + * |
|
50 | + * @param string $configBranch Start looking in this branch. |
|
51 | + * @return null|Puc_v4p4_Vcs_Reference |
|
52 | + */ |
|
53 | + abstract public function chooseReference($configBranch); |
|
54 | + |
|
55 | + /** |
|
56 | + * Get the readme.txt file from the remote repository and parse it |
|
57 | + * according to the plugin readme standard. |
|
58 | + * |
|
59 | + * @param string $ref Tag or branch name. |
|
60 | + * @return array Parsed readme. |
|
61 | + */ |
|
62 | + public function getRemoteReadme($ref = 'master') { |
|
63 | + $fileContents = $this->getRemoteFile($this->getLocalReadmeName(), $ref); |
|
64 | + if ( empty($fileContents) ) { |
|
65 | + return array(); |
|
66 | + } |
|
67 | + |
|
68 | + $parser = new PucReadmeParser(); |
|
69 | + return $parser->parse_readme_contents($fileContents); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get the case-sensitive name of the local readme.txt file. |
|
74 | + * |
|
75 | + * In most cases it should just be called "readme.txt", but some plugins call it "README.txt", |
|
76 | + * "README.TXT", or even "Readme.txt". Most VCS are case-sensitive so we need to know the correct |
|
77 | + * capitalization. |
|
78 | + * |
|
79 | + * Defaults to "readme.txt" (all lowercase). |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getLocalReadmeName() { |
|
84 | + static $fileName = null; |
|
85 | + if ( $fileName !== null ) { |
|
86 | + return $fileName; |
|
87 | + } |
|
88 | + |
|
89 | + $fileName = 'readme.txt'; |
|
90 | + if ( isset($this->localDirectory) ) { |
|
91 | + $files = scandir($this->localDirectory); |
|
92 | + if ( !empty($files) ) { |
|
93 | + foreach ($files as $possibleFileName) { |
|
94 | + if ( strcasecmp($possibleFileName, 'readme.txt') === 0 ) { |
|
95 | + $fileName = $possibleFileName; |
|
96 | + break; |
|
97 | + } |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + return $fileName; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Get a branch. |
|
106 | + * |
|
107 | + * @param string $branchName |
|
108 | + * @return Puc_v4p4_Vcs_Reference|null |
|
109 | + */ |
|
110 | + abstract public function getBranch($branchName); |
|
111 | + |
|
112 | + /** |
|
113 | + * Get a specific tag. |
|
114 | + * |
|
115 | + * @param string $tagName |
|
116 | + * @return Puc_v4p4_Vcs_Reference|null |
|
117 | + */ |
|
118 | + abstract public function getTag($tagName); |
|
119 | + |
|
120 | + /** |
|
121 | + * Get the tag that looks like the highest version number. |
|
122 | + * (Implementations should skip pre-release versions if possible.) |
|
123 | + * |
|
124 | + * @return Puc_v4p4_Vcs_Reference|null |
|
125 | + */ |
|
126 | + abstract public function getLatestTag(); |
|
127 | + |
|
128 | + /** |
|
129 | + * Check if a tag name string looks like a version number. |
|
130 | + * |
|
131 | + * @param string $name |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | + protected function looksLikeVersion($name) { |
|
135 | + //Tag names may be prefixed with "v", e.g. "v1.2.3". |
|
136 | + $name = ltrim($name, 'v'); |
|
137 | + |
|
138 | + //The version string must start with a number. |
|
139 | + if ( !is_numeric(substr($name, 0, 1)) ) { |
|
140 | + return false; |
|
141 | + } |
|
142 | + |
|
143 | + //The goal is to accept any SemVer-compatible or "PHP-standardized" version number. |
|
144 | + return (preg_match('@^(\d{1,5}?)(\.\d{1,10}?){0,4}?($|[abrdp+_\-]|\s)@i', $name) === 1); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Check if a tag appears to be named like a version number. |
|
149 | + * |
|
150 | + * @param stdClass $tag |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + protected function isVersionTag($tag) { |
|
154 | + $property = $this->tagNameProperty; |
|
155 | + return isset($tag->$property) && $this->looksLikeVersion($tag->$property); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Sort a list of tags as if they were version numbers. |
|
160 | + * Tags that don't look like version number will be removed. |
|
161 | + * |
|
162 | + * @param stdClass[] $tags Array of tag objects. |
|
163 | + * @return stdClass[] Filtered array of tags sorted in descending order. |
|
164 | + */ |
|
165 | + protected function sortTagsByVersion($tags) { |
|
166 | + //Keep only those tags that look like version numbers. |
|
167 | + $versionTags = array_filter($tags, array($this, 'isVersionTag')); |
|
168 | + //Sort them in descending order. |
|
169 | + usort($versionTags, array($this, 'compareTagNames')); |
|
170 | + |
|
171 | + return $versionTags; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Compare two tags as if they were version number. |
|
176 | + * |
|
177 | + * @param stdClass $tag1 Tag object. |
|
178 | + * @param stdClass $tag2 Another tag object. |
|
179 | + * @return int |
|
180 | + */ |
|
181 | + protected function compareTagNames($tag1, $tag2) { |
|
182 | + $property = $this->tagNameProperty; |
|
183 | + if ( !isset($tag1->$property) ) { |
|
184 | + return 1; |
|
185 | + } |
|
186 | + if ( !isset($tag2->$property) ) { |
|
187 | + return -1; |
|
188 | + } |
|
189 | + return -version_compare(ltrim($tag1->$property, 'v'), ltrim($tag2->$property, 'v')); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Get the contents of a file from a specific branch or tag. |
|
194 | + * |
|
195 | + * @param string $path File name. |
|
196 | + * @param string $ref |
|
197 | + * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error. |
|
198 | + */ |
|
199 | + abstract public function getRemoteFile($path, $ref = 'master'); |
|
200 | + |
|
201 | + /** |
|
202 | + * Get the timestamp of the latest commit that changed the specified branch or tag. |
|
203 | + * |
|
204 | + * @param string $ref Reference name (e.g. branch or tag). |
|
205 | + * @return string|null |
|
206 | + */ |
|
207 | + abstract public function getLatestCommitTime($ref); |
|
208 | + |
|
209 | + /** |
|
210 | + * Get the contents of the changelog file from the repository. |
|
211 | + * |
|
212 | + * @param string $ref |
|
213 | + * @param string $localDirectory Full path to the local plugin or theme directory. |
|
214 | + * @return null|string The HTML contents of the changelog. |
|
215 | + */ |
|
216 | + public function getRemoteChangelog($ref, $localDirectory) { |
|
217 | + $filename = $this->findChangelogName($localDirectory); |
|
218 | + if ( empty($filename) ) { |
|
219 | + return null; |
|
220 | + } |
|
221 | + |
|
222 | + $changelog = $this->getRemoteFile($filename, $ref); |
|
223 | + if ( $changelog === null ) { |
|
224 | + return null; |
|
225 | + } |
|
226 | + |
|
227 | + /** @noinspection PhpUndefinedClassInspection */ |
|
228 | + return Parsedown::instance()->text($changelog); |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Guess the name of the changelog file. |
|
233 | + * |
|
234 | + * @param string $directory |
|
235 | + * @return string|null |
|
236 | + */ |
|
237 | + protected function findChangelogName($directory = null) { |
|
238 | + if ( !isset($directory) ) { |
|
239 | + $directory = $this->localDirectory; |
|
240 | + } |
|
241 | + if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) { |
|
242 | + return null; |
|
243 | + } |
|
244 | + |
|
245 | + $possibleNames = array('CHANGES.md', 'CHANGELOG.md', 'changes.md', 'changelog.md'); |
|
246 | + $files = scandir($directory); |
|
247 | + $foundNames = array_intersect($possibleNames, $files); |
|
248 | + |
|
249 | + if ( !empty($foundNames) ) { |
|
250 | + return reset($foundNames); |
|
251 | + } |
|
252 | + return null; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Set authentication credentials. |
|
257 | + * |
|
258 | + * @param $credentials |
|
259 | + */ |
|
260 | + public function setAuthentication($credentials) { |
|
261 | + $this->credentials = $credentials; |
|
262 | + } |
|
263 | + |
|
264 | + public function isAuthenticationEnabled() { |
|
265 | + return !empty($this->credentials); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @param string $url |
|
270 | + * @return string |
|
271 | + */ |
|
272 | + public function signDownloadUrl($url) { |
|
273 | + return $url; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @param string $filterName |
|
278 | + */ |
|
279 | + public function setHttpFilterName($filterName) { |
|
280 | + $this->httpFilterName = $filterName; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * @param string $directory |
|
285 | + */ |
|
286 | + public function setLocalDirectory($directory) { |
|
287 | + if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) { |
|
288 | + $this->localDirectory = null; |
|
289 | + } else { |
|
290 | + $this->localDirectory = $directory; |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * @param string $slug |
|
296 | + */ |
|
297 | + public function setSlug($slug) { |
|
298 | + $this->slug = $slug; |
|
299 | + } |
|
300 | + } |
|
301 | 301 | |
302 | 302 | endif; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !class_exists('Puc_v4p4_Vcs_Api') ): |
|
2 | +if (!class_exists('Puc_v4p4_Vcs_Api')): |
|
3 | 3 | |
4 | 4 | abstract class Puc_v4p4_Vcs_Api { |
5 | 5 | protected $tagNameProperty = 'name'; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function getRemoteReadme($ref = 'master') { |
63 | 63 | $fileContents = $this->getRemoteFile($this->getLocalReadmeName(), $ref); |
64 | - if ( empty($fileContents) ) { |
|
64 | + if (empty($fileContents)) { |
|
65 | 65 | return array(); |
66 | 66 | } |
67 | 67 | |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getLocalReadmeName() { |
84 | 84 | static $fileName = null; |
85 | - if ( $fileName !== null ) { |
|
85 | + if ($fileName !== null) { |
|
86 | 86 | return $fileName; |
87 | 87 | } |
88 | 88 | |
89 | 89 | $fileName = 'readme.txt'; |
90 | - if ( isset($this->localDirectory) ) { |
|
90 | + if (isset($this->localDirectory)) { |
|
91 | 91 | $files = scandir($this->localDirectory); |
92 | - if ( !empty($files) ) { |
|
92 | + if (!empty($files)) { |
|
93 | 93 | foreach ($files as $possibleFileName) { |
94 | - if ( strcasecmp($possibleFileName, 'readme.txt') === 0 ) { |
|
94 | + if (strcasecmp($possibleFileName, 'readme.txt') === 0) { |
|
95 | 95 | $fileName = $possibleFileName; |
96 | 96 | break; |
97 | 97 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $name = ltrim($name, 'v'); |
137 | 137 | |
138 | 138 | //The version string must start with a number. |
139 | - if ( !is_numeric(substr($name, 0, 1)) ) { |
|
139 | + if (!is_numeric(substr($name, 0, 1))) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | */ |
181 | 181 | protected function compareTagNames($tag1, $tag2) { |
182 | 182 | $property = $this->tagNameProperty; |
183 | - if ( !isset($tag1->$property) ) { |
|
183 | + if (!isset($tag1->$property)) { |
|
184 | 184 | return 1; |
185 | 185 | } |
186 | - if ( !isset($tag2->$property) ) { |
|
186 | + if (!isset($tag2->$property)) { |
|
187 | 187 | return -1; |
188 | 188 | } |
189 | 189 | return -version_compare(ltrim($tag1->$property, 'v'), ltrim($tag2->$property, 'v')); |
@@ -215,12 +215,12 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function getRemoteChangelog($ref, $localDirectory) { |
217 | 217 | $filename = $this->findChangelogName($localDirectory); |
218 | - if ( empty($filename) ) { |
|
218 | + if (empty($filename)) { |
|
219 | 219 | return null; |
220 | 220 | } |
221 | 221 | |
222 | 222 | $changelog = $this->getRemoteFile($filename, $ref); |
223 | - if ( $changelog === null ) { |
|
223 | + if ($changelog === null) { |
|
224 | 224 | return null; |
225 | 225 | } |
226 | 226 | |
@@ -235,10 +235,10 @@ discard block |
||
235 | 235 | * @return string|null |
236 | 236 | */ |
237 | 237 | protected function findChangelogName($directory = null) { |
238 | - if ( !isset($directory) ) { |
|
238 | + if (!isset($directory)) { |
|
239 | 239 | $directory = $this->localDirectory; |
240 | 240 | } |
241 | - if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) { |
|
241 | + if (empty($directory) || !is_dir($directory) || ($directory === '.')) { |
|
242 | 242 | return null; |
243 | 243 | } |
244 | 244 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | $files = scandir($directory); |
247 | 247 | $foundNames = array_intersect($possibleNames, $files); |
248 | 248 | |
249 | - if ( !empty($foundNames) ) { |
|
249 | + if (!empty($foundNames)) { |
|
250 | 250 | return reset($foundNames); |
251 | 251 | } |
252 | 252 | return null; |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | * @param string $directory |
285 | 285 | */ |
286 | 286 | public function setLocalDirectory($directory) { |
287 | - if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) { |
|
287 | + if (empty($directory) || !is_dir($directory) || ($directory === '.')) { |
|
288 | 288 | $this->localDirectory = null; |
289 | 289 | } else { |
290 | 290 | $this->localDirectory = $directory; |