AutocompletePostListLoader.php
2 months ago
DateTime.php
1 year ago
Emoji.php
2 months ago
Functions.php
1 week ago
Notice.php
3 years ago
Posts.php
3 years ago
Readme.php
3 years ago
index.php
3 years ago
Readme.php
54 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\WP; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class Readme { |
| 9 | public static function parseChangelog($readmeTxt, $limit = null) { |
| 10 | // Extract changelog section of the readme.txt |
| 11 | preg_match('/== Changelog ==(.*?)(\n==|$)/is', $readmeTxt, $changelog); |
| 12 | |
| 13 | if (empty($changelog[1])) { |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | // Get changelog entries |
| 18 | $entries = preg_split('/\n(?=\=)/', trim($changelog[1]), -1, PREG_SPLIT_NO_EMPTY); |
| 19 | |
| 20 | if (empty($entries)) { |
| 21 | return false; |
| 22 | } |
| 23 | |
| 24 | $c = 0; |
| 25 | $changelog = []; |
| 26 | |
| 27 | foreach ($entries as $entry) { |
| 28 | // Locate version header and changes list |
| 29 | preg_match('/=(.*?)=(.*)/s', $entry, $parts); |
| 30 | |
| 31 | if (empty($parts[1]) || empty($parts[2])) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | $header = trim($parts[1]); |
| 36 | $list = trim($parts[2]); |
| 37 | |
| 38 | // Get individual items from the list |
| 39 | $list = preg_split('/(^|\n)[\* ]*/', $list, -1, PREG_SPLIT_NO_EMPTY); |
| 40 | |
| 41 | $changelog[] = [ |
| 42 | 'version' => $header, |
| 43 | 'changes' => $list, |
| 44 | ]; |
| 45 | |
| 46 | if (++$c == $limit) { |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return $changelog; |
| 52 | } |
| 53 | } |
| 54 |