Display changelog from readme.txt on Update page [MAILPOET-708]
This commit is contained in:
@@ -17,6 +17,7 @@ use MailPoet\Listing;
|
||||
use MailPoet\Util\License\Features\Subscribers as SubscribersFeature;
|
||||
use MailPoet\WP\DateTime;
|
||||
use MailPoet\WP\Notice as WPNotice;
|
||||
use MailPoet\WP\Readme;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@@ -242,6 +243,14 @@ class Menu {
|
||||
'sub_menu' => 'mailpoet-newsletters'
|
||||
);
|
||||
|
||||
$readme_file = Env::$path . '/readme.txt';
|
||||
if(file_exists($readme_file)) {
|
||||
$changelog = Readme::parseChangelog(file_get_contents($readme_file), 2);
|
||||
if($changelog) {
|
||||
$data['changelog'] = $changelog;
|
||||
}
|
||||
}
|
||||
|
||||
$this->displayPage('update.html', $data);
|
||||
}
|
||||
|
||||
|
49
lib/WP/Readme.php
Normal file
49
lib/WP/Readme.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace MailPoet\WP;
|
||||
|
||||
class Readme {
|
||||
static function parseChangelog($readme_txt, $limit = null) {
|
||||
// Extract changelog section of the readme.txt
|
||||
preg_match('/== Changelog ==(.*?)(\n==|$)/is', $readme_txt, $changelog);
|
||||
|
||||
if(empty($changelog[1])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get changelog entries
|
||||
$entries = preg_split('/\n(?=\=)/', trim($changelog[1]), -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
if(empty($entries)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
$changelog = array();
|
||||
|
||||
foreach($entries as $entry) {
|
||||
// Locate version header and changes list
|
||||
preg_match('/=(.*?)=(.*)/s', $entry, $parts);
|
||||
|
||||
if(empty($parts[1]) || empty($parts[2])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$header = trim($parts[1]);
|
||||
$list = trim($parts[2]);
|
||||
|
||||
// Get individual items from the list
|
||||
$list = preg_split('/(^|\n)[\* ]*/', $list, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$changelog[] = array(
|
||||
'version' => $header,
|
||||
'changes' => $list,
|
||||
);
|
||||
|
||||
if(++$c == $limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $changelog;
|
||||
}
|
||||
}
|
28
tests/unit/WP/ReadmeTest.php
Normal file
28
tests/unit/WP/ReadmeTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
use \MailPoet\WP\Readme;
|
||||
|
||||
class ReadmeTest extends MailPoetTest {
|
||||
function _before() {
|
||||
// Sample taken from https://wordpress.org/plugins/about/readme.txt
|
||||
$this->data = file_get_contents(dirname(__FILE__) . '/ReadmeTestData.txt');
|
||||
}
|
||||
|
||||
function testItParsesChangelog() {
|
||||
$result = Readme::parseChangelog($this->data);
|
||||
expect(count($result))->equals(2);
|
||||
expect(count($result[0]['changes']))->equals(2);
|
||||
expect(count($result[1]['changes']))->equals(1);
|
||||
}
|
||||
|
||||
function testItRespectsLimitOfParsedItems() {
|
||||
$result = Readme::parseChangelog($this->data, 1);
|
||||
expect(count($result))->equals(1);
|
||||
}
|
||||
|
||||
function testItReturnsFalseOnMalformedData() {
|
||||
$result = Readme::parseChangelog("");
|
||||
expect($result)->false();
|
||||
$result = Readme::parseChangelog("== Changelog ==\n\n\n=\n==");
|
||||
expect($result)->false();
|
||||
}
|
||||
}
|
116
tests/unit/WP/ReadmeTestData.txt
Normal file
116
tests/unit/WP/ReadmeTestData.txt
Normal file
@@ -0,0 +1,116 @@
|
||||
=== Plugin Name ===
|
||||
Contributors: (this should be a list of wordpress.org userid's)
|
||||
Donate link: http://example.com/
|
||||
Tags: comments, spam
|
||||
Requires at least: 4.6
|
||||
Tested up to: 4.7
|
||||
Stable tag: 4.3
|
||||
License: GPLv2 or later
|
||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
Here is a short description of the plugin. This should be no more than 150 characters. No markup here.
|
||||
|
||||
== Description ==
|
||||
|
||||
This is the long description. No limit, and you can use Markdown (as well as in the following sections).
|
||||
|
||||
For backwards compatibility, if this section is missing, the full length of the short description will be used, and
|
||||
Markdown parsed.
|
||||
|
||||
A few notes about the sections above:
|
||||
|
||||
* "Contributors" is a comma separated list of wordpress.org usernames
|
||||
* "Tags" is a comma separated list of tags that apply to the plugin
|
||||
* "Requires at least" is the lowest version that the plugin will work on
|
||||
* "Tested up to" is the highest version that you've *successfully used to test the plugin*. Note that it might work on
|
||||
higher versions... this is just the highest one you've verified.
|
||||
* Stable tag should indicate the Subversion "tag" of the latest stable version, or "trunk," if you use `/trunk/` for
|
||||
stable.
|
||||
|
||||
Note that the `readme.txt` of the stable tag is the one that is considered the defining one for the plugin, so
|
||||
if the `/trunk/readme.txt` file says that the stable tag is `4.3`, then it is `/tags/4.3/readme.txt` that'll be used
|
||||
for displaying information about the plugin. In this situation, the only thing considered from the trunk `readme.txt`
|
||||
is the stable tag pointer. Thus, if you develop in trunk, you can update the trunk `readme.txt` to reflect changes in
|
||||
your in-development version, without having that information incorrectly disclosed about the current stable version
|
||||
that lacks those changes -- as long as the trunk's `readme.txt` points to the correct stable tag.
|
||||
|
||||
If no stable tag is provided, it is assumed that trunk is stable, but you should specify "trunk" if that's where
|
||||
you put the stable version, in order to eliminate any doubt.
|
||||
|
||||
== Installation ==
|
||||
|
||||
This section describes how to install the plugin and get it working.
|
||||
|
||||
e.g.
|
||||
|
||||
1. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly.
|
||||
1. Activate the plugin through the 'Plugins' screen in WordPress
|
||||
1. Use the Settings->Plugin Name screen to configure the plugin
|
||||
1. (Make your instructions match the desired user flow for activating and installing your plugin. Include any steps that might be needed for explanatory purposes)
|
||||
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= A question that someone might have =
|
||||
|
||||
An answer to that question.
|
||||
|
||||
= What about foo bar? =
|
||||
|
||||
Answer to foo bar dilemma.
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
|
||||
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
|
||||
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
|
||||
(or jpg, jpeg, gif).
|
||||
2. This is the second screen shot
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.0 =
|
||||
* A change since the previous version.
|
||||
* Another change.
|
||||
|
||||
= 0.5 =
|
||||
* List versions from most recent at top to oldest at bottom.
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 1.0 =
|
||||
Upgrade notices describe the reason a user should upgrade. No more than 300 characters.
|
||||
|
||||
= 0.5 =
|
||||
This version fixes a security related bug. Upgrade immediately.
|
||||
|
||||
== Arbitrary section ==
|
||||
|
||||
You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated
|
||||
plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or
|
||||
"installation." Arbitrary sections will be shown below the built-in sections outlined above.
|
||||
|
||||
== A brief Markdown Example ==
|
||||
|
||||
Ordered list:
|
||||
|
||||
1. Some feature
|
||||
1. Another feature
|
||||
1. Something else about the plugin
|
||||
|
||||
Unordered list:
|
||||
|
||||
* something
|
||||
* something else
|
||||
* third thing
|
||||
|
||||
Here's a link to [WordPress](http://wordpress.org/ "Your favorite software") and one to [Markdown's Syntax Documentation][markdown syntax].
|
||||
Titles are optional, naturally.
|
||||
|
||||
[markdown syntax]: http://daringfireball.net/projects/markdown/syntax
|
||||
"Markdown is what the parser uses to process much of the readme file"
|
||||
|
||||
Markdown uses email style notation for blockquotes and I've been told:
|
||||
> Asterisks for *emphasis*. Double it up for **strong**.
|
||||
|
||||
`<?php code(); // goes in backticks ?>`
|
@@ -23,30 +23,19 @@
|
||||
|
||||
<div id="mailpoet-changelog" clas="feature-section one-col">
|
||||
<h2><%= __("List of Changes") %></h2>
|
||||
<h3>3.0.0-beta.7.1 - 2016-12-06</h3>
|
||||
<% if changelog %>
|
||||
<% for item in changelog %>
|
||||
<h3><%= item.version %></h3>
|
||||
<ul>
|
||||
<li>Improved: allow user to restart sending after sending method failure;</li>
|
||||
<li>Fixed: subscribers are not added to lists after import;</li>
|
||||
<li>Fixed: sending should stop when newsletter is trashed;</li>
|
||||
<li>Fixed: update database schema after an update which fixes an SQL error;</li>
|
||||
<li>Fixed: status of sent newsletters is showing "paused" instead of "sent";</li>
|
||||
<li>Fixed: dividers in Automatic Latest Posts posts are not displayed. Thx Gregor!;</li>
|
||||
<li>Fixed: shortcodes (ie, first name) are not rendered when sending a preview;</li>
|
||||
<li>Fixed: count of confirmed subscribers only in step 2 of import is erroneous.</li>
|
||||
</ul>
|
||||
<br>
|
||||
<h3>3.0.0-beta.6 - 2016-11-29</h3>
|
||||
<ul>
|
||||
<li>Added: "bounced" status has been added to subscribers;</li>
|
||||
<li>Improved: execution time enforced between individual send operations. Avoids duplicate sending on really slow servers;</li>
|
||||
<li>Improved: Welcome emails are given higher priority for sending;</li>
|
||||
<li>Fixed: Welcome emails are not scheduled for WP users;</li>
|
||||
<li>Fixed: Unicode characters in FROM/REPLY-TO/TO fields are not rendered;</li>
|
||||
<li>Fixed: sending HTML emails with Amazon SES works again. Kudos Alex for reporting;</li>
|
||||
<li>Fixed: import fails when subscriber already exists in the database but the email is in different case format. Thx Ellen for telling us;</li>
|
||||
<li>Fixed: ampersand char ("&") inside the subject line won't throw errors in browser preview. Thanks Michel for reporting.</li>
|
||||
<% for change in item.changes %>
|
||||
<li><%= change %></li>
|
||||
<% endfor %>
|
||||
</ul>
|
||||
<br>
|
||||
<% endfor %>
|
||||
<% else %>
|
||||
<p style="text-align: center"><%= __("See readme.txt for a changelog.") %></p>
|
||||
<% endif %>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
Reference in New Issue
Block a user