<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[3477] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Move readme classes into their own namespace.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/3477">3477</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/3477","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>obenland</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-06-19 20:40:01 +0000 (Sun, 19 Jun 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugin Directory: Move readme classes into their own namespace.
See <a href="http://meta.trac.wordpress.org/ticket/1584">#1584</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclasscustomizationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryshortcodesclassuploadhandlerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryreadmeclassparserphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryreadmeclassvalidatorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclassreadmevalidatorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-readme-validator.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassreadmeparserphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclasscustomizationsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php 2016-06-19 19:34:19 UTC (rev 3476)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php 2016-06-19 20:40:01 UTC (rev 3477)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,6 +2,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\Admin;
</span><span class="cx" style="display: block; padding: 0 10px"> use \WordPressdotorg\Plugin_Directory;
</span><span class="cx" style="display: block; padding: 0 10px"> use \WordPressdotorg\Plugin_Directory\Tools;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use \WordPressdotorg\Plugin_Directory\Readme\Validator;
</ins><span class="cx" style="display: block; padding: 0 10px"> use \WordPressdotorg\Plugin_Directory\Admin\List_Table\Plugin_Posts;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -135,7 +136,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> add_submenu_page( 'edit.php?post_type=plugin', 'Plugin Handbook', 'Plugin Handbook', 'read', 'handbook', function() {} );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $readme_validator = Readme_Validator::instance();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $readme_validator = Validator::instance();
</ins><span class="cx" style="display: block; padding: 0 10px"> add_submenu_page( 'edit.php?post_type=plugin', 'Readme Validator', 'Readme Validator', 'read', 'readme_validator', array( $readme_validator, 'display' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! current_user_can( 'manage_options' ) ) {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclassreadmevalidatorphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-readme-validator.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-readme-validator.php 2016-06-19 19:34:19 UTC (rev 3476)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-readme-validator.php 2016-06-19 20:40:01 UTC (rev 3477)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,207 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-namespace WordPressdotorg\Plugin_Directory\Admin;
-use \WordPressdotorg\Plugin_Directory\Readme_Parser;
-use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
-
-/**
- * A wp-admin interface to validate readme files.
- *
- * @package WordPressdotorg\Plugin_Directory\Admin
- */
-class Readme_Validator {
-
- /**
- * Fetch the instance of the Readme_Validator class.
- *
- * @static
- */
- public static function instance() {
- static $instance = null;
-
- return ! is_null( $instance ) ? $instance : $instance = new Readme_Validator();
- }
-
- /**
- * Constructor.
- */
- private function __construct() {
- add_action( 'plugin_page_readme_validator', array( $this, 'add_form_fields' ) );
- add_action( 'plugin_page_readme_validator', array( $this, 'validate' ) );
- }
-
- /**
- * Displays a for to validate readme.txt files and blobs of text.
- */
- public function display() {
- ?>
- <div class="wrap">
- <h2><?php _e( 'WordPress Plugin readme.txt Validator', 'wporg-plugins' ); ?></h2>
- <?php settings_errors( 'wporg-plugins-readme' ); ?>
- <form method="post" action="<?php echo esc_url( add_query_arg( array( 'post_type' => 'plugin', 'page' => 'readme_validator' ), admin_url( 'edit.php' ) ) ); ?>">
- <?php
- wp_nonce_field( 'validate-readme' );
- do_settings_sections( 'readme_validator' );
- submit_button( __( 'Validate', 'wporg-plugins' ) );
- ?>
- </form>
- </div>
- <?php
- }
-
- /**
- * Registers form fields for this admin page.
- */
- public function add_form_fields() {
- add_settings_section( 'default', '', array( $this, 'section_description' ), 'readme_validator' );
-
- add_settings_field( 'readme_url', __( 'URL to readme.txt file', 'wporg-plugins' ), array( $this, 'url_input' ), 'readme_validator', 'default', array(
- 'label_for' => 'readme_url',
- ) );
- add_settings_field( 'readme_text', __( 'Text of readme.txt', 'wporg-plugins' ), array( $this, 'textarea' ), 'readme_validator', 'default', array(
- 'label_for' => 'readme_contents',
- ) );
- }
-
- /**
- * Validates readme.txt contents and adds feedback.
- */
- public function validate() {
- if ( ! isset( $_REQUEST['_wpnonce'] ) ) {
- return;
- }
- check_admin_referer( 'validate-readme' );
-
- $readme = '';
- $temp_file = Filesystem::temp_directory() . '/readme.txt';
- $warnings = array();
- $notes = array();
-
- if ( ! empty( $_REQUEST['readme_url'] ) ) {
- $url = esc_url_raw( $_REQUEST['readme_url'] );
-
- if ( strtolower( substr( $url, -10 ) ) != 'readme.txt' ) {
- /* Translators: File name; */
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( 'URL must end in %s!', 'wporg-plugins' ), '<code>readme.txt</code>' ) );
- return;
- }
-
- if ( ! $readme = @file_get_contents( $url ) ) {
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', __( 'Invalid readme.txt URL.', 'wporg-plugins' ) );
- return;
- }
-
- } elseif ( ! empty( $_REQUEST['readme_contents'] ) && is_string( $_REQUEST['readme_contents'] ) ) {
- $readme = wp_unslash( $_REQUEST['readme_contents'] );
- }
-
- if ( empty( $readme ) ) {
- return;
- }
-
- file_put_contents( $temp_file, $readme );
- $readme = new Readme_Parser( $temp_file );
-
- // Fatal errors.
- if ( empty( $readme->name ) ) {
- /* Translators: Plugin header tag; */
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( "Fatal Error:\nNo plugin name detected. Plugin names look like: %s", 'wporg-plugins' ), '<code>=== Plugin Name ===</code>' ) );
- return;
- }
-
- // Warnings.
- if ( empty( $readme->requires ) ) {
- /* Translators: Plugin header tag; */
- $warnings[] = sprintf( __( '%s is missing.', 'wporg-plugins' ), '<code>Requires at least</code>' );
- }
- if ( empty( $readme->tested ) ) {
- /* Translators: Plugin header tag; */
- $warnings[] = sprintf( __( '%s is missing.', 'wporg-plugins' ), '<code>Tested up to</code>' );
- }
- if ( empty( $readme->stable_tag ) ) {
- /* Translators: 1: Plugin header tag; 2: SVN directory; 3: Plugin header tag; */
- $warnings[] = sprintf( __( '%1$s is missing. Hint: If you treat %2$s as stable, put %3$s.', 'wporg-plugins' ), '<code>Stable tag</code>', '<code>/trunk/</code>', '<code>Stable tag: trunk</code>' );
- }
- if ( ! count( $readme->contributors ) ) {
- /* Translators: Plugin header tag; */
- $warnings[] = sprintf( __( 'No %s listed.', 'wporg-plugins' ), '<code>Contributors</code>' );
- }
-
- if ( $warnings ) {
- $message = __( 'Warnings:', 'wporg-plugins' ) . "\n<ul class='warning error'>\n";
- foreach ( $warnings as $warning ) {
- $message .= "<li>$warning</li>\n";
- }
- $message .= "</ul>\n</div>";
-
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-warning' );
- return;
- }
-
- // Notes.
- if ( empty( $readme->sections['faq'] ) ) {
- /* Translators: Plugin header tag; */
- $notes[] = sprintf( __( 'No %s section was found', 'wporg-plugins' ), '<code>== Frequently Asked Questions ==</code>' );
- }
- if ( empty( $readme->sections['changelog'] ) ) {
- /* Translators: Plugin header tag; */
- $notes[] = sprintf( __( 'No %s section was found', 'wporg-plugins' ), '<code>== Changelog ==</code>' );
- }
- if ( empty( $readme->upgrade_notice ) ) {
- /* Translators: Plugin header tag; */
- $notes[] = sprintf( __( 'No %s section was found', 'wporg-plugins' ), '<code>== Upgrade Notice ==</code>' );
- }
- if ( empty( $readme->screenshots ) ) {
- /* Translators: Plugin header tag; */
- $notes[] = sprintf( __( 'No %s section was found', 'wporg-plugins' ), '<code>== Screenshots ==</code>' );
- }
- if ( empty( $readme->donate_link ) ) {
- $notes[] = __( 'No donate link was found', 'wporg-plugins' );
- }
-
- if ( $notes ) {
- $message = __( 'Notes:' ) . "\n<ul class='note error'>\n";
- foreach ( $notes as $note ) {
- $message .= "<li>$note</li>\n";
- }
- $message .= "</ul>\n</div>";
-
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-info' );
- return;
- }
-
- /* Translators: File name; */
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( 'Your %s rocks. Seriously. Flying colors.', 'wporg-plugins' ), '<code>readme.txt</code>' ), 'updated' );
- }
-
- /**
- * Help text for the form following after it.
- */
- public function section_description() {
- /* Translators: File name; */
- echo '<p>' . sprintf( __( 'Enter the URL to your %s file or paste its content below.' ), '<code>readme.txt</code>' ) . '</p>';
- }
-
- /**
- * Displays an input field for the readme.txt URL.
- */
- public function url_input() {
- $url = empty( $_REQUEST['readme_url'] ) ? '' : $_REQUEST['readme_url'];
- ?>
- <label>
- <input type="url" id="readme_url" name="readme_url" size="70" value="<?php echo esc_url( $url ); ?>" />
- </label>
- <?php
- }
-
- /**
- * Displays a textarea for readme.txt blobs.
- */
- public function textarea() {
- $text = empty( $_REQUEST['readme_contents'] ) ? '' : wp_unslash( $_REQUEST['readme_contents'] );
- ?>
- <label>
- <textarea type="text" id="readme_contents" class="large-text" name="readme_contents" cols="50" rows="10"><?php echo esc_textarea( $text ); ?></textarea>
- </label>
- <?php
- }
-}
</del></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassreadmeparserphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php 2016-06-19 19:34:19 UTC (rev 3476)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php 2016-06-19 20:40:01 UTC (rev 3477)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,408 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-namespace WordPressdotorg\Plugin_Directory;
-
-/**
- * WordPress.org Plugin Readme Parser.
- *
- * Based on Baikonur_ReadmeParser from https://github.com/rmccue/WordPress-Readme-Parser
- *
- * @package WordPressdotorg\Plugin_Directory
- */
-class Readme_Parser {
- public $name = '';
- public $tags = array();
- public $requires = '';
- public $tested = '';
- public $contributors = array();
- public $stable_tag = '';
- public $donate_link = '';
- public $short_description = '';
- public $sections = array();
- public $upgrade_notice = array();
- public $screenshots = array();
-
- // These are the readme sections which we expect
- private $expected_sections = array(
- 'description',
- 'installation',
- 'faq',
- 'screenshots',
- 'changelog',
- 'upgrade_notice',
- 'other_notes',
- );
-
- // We alias these sections, from => to
- private $alias_sections = array(
- 'frequently_asked_questions' => 'faq',
- 'change_log' => 'changelog',
- 'screenshot' => 'screenshots',
- );
-
- // These are the valid header mappings for the header
- private $valid_headers = array(
- 'tested' => 'tested',
- 'tested up to' => 'tested',
- 'requires' => 'requires',
- 'requires at least' => 'requires',
- 'tags' => 'tags',
- 'contributors' => 'contributors',
- 'donate link' => 'donate_link',
- 'stable tag' => 'stable_tag',
- );
-
- public function __construct( $file ) {
- if ( $file ) {
- $this->parse_readme( $file );
- }
- }
-
- protected function parse_readme( $file ) {
- $contents = file_get_contents( $file );
- $contents = preg_split( '!\R!', $contents );
-
- $contents = array_map( array( $this, 'strip_newlines' ), $contents );
-
- // Strip UTF8 BOM if present
- if ( strpos( $contents[0], "\xEF\xBB\xBF" ) === 0 ) {
- $contents[0] = substr( $contents[0], 3 );
- }
-
- // Convert UTF-16 files
- if ( strpos( $contents[0], "\xFF\xFE" ) === 0 ) {
- foreach ( $contents as $i => $line ) {
- $contents[$i] = mb_convert_encoding( $line, 'UTF-8', 'UTF-16' );
- }
- }
-
- $line = $this->get_first_nonwhitespace( $contents );
- $this->name = $this->sanitize_text( trim( $line, "#= \t\0\x0B" ) );
-
- // Strip Github style header\n==== underlines
- if ( '' === trim( $contents[0], '=-' ) ) {
- array_shift( $contents );
- }
-
- // Handle readme's which do `=== Plugin Name ===\nMy SuperAwesomePlugin Name\n...`
- if ( 'plugin name' == strtolower( $this->name ) ) {
- $this->name = $line = $this->get_first_nonwhitespace( $contents );
- // Ensure that the line read wasn't an actual header or description
- if ( strlen( $line ) > 50 || preg_match( '~^(' . implode( '|', array_keys( $this->valid_headers ) ) . ')\s*:~i', $line ) ) {
- $this->name = false;
- array_unshift( $contents, $line );
- }
- }
-
- // Parse headers
- $headers = array();
-
- $line = $this->get_first_nonwhitespace( $contents );
- do {
- $value = null;
- if ( strpos( $line, ':' ) === false ) {
- // Some plugins have line-breaks within the headers.
- if ( ! empty( $line ) ) {
- break;
- } else {
- continue;
- }
- }
-
- $bits = explode( ':', trim( $line ), 2 );
- list( $key, $value ) = $bits;
- $key = strtolower( trim( $key, " \t*-\r\n" ) );
- if ( isset( $this->valid_headers[ $key ] ) ) {
- $headers[ $this->valid_headers[ $key ] ] = trim( $value );
- }
- } while ( ( $line = array_shift( $contents ) ) !== null );
- array_unshift( $contents, $line );
-
- if ( ! empty( $headers['tags'] ) ) {
- $this->tags = explode( ',', $headers['tags'] );
- $this->tags = array_map( 'trim', $this->tags );
- }
- if ( ! empty( $headers['requires'] ) ) {
- $this->requires = $headers['requires'];
- }
- if ( ! empty( $headers['tested'] ) ) {
- $this->tested = $headers['tested'];
- }
- if ( ! empty( $headers['contributors'] ) ) {
- $this->contributors = explode( ',', $headers['contributors'] );
- $this->contributors = array_map( 'trim', $this->contributors );
- $this->contributors = $this->sanitize_contributors( $this->contributors );
- }
- if ( ! empty( $headers['stable_tag'] ) ) {
- $this->stable_tag = $this->sanitize_stable_tag( $headers['stable_tag'] );
- }
- if ( ! empty( $headers['donate_link'] ) ) {
- $this->donate_link = $headers['donate_link'];
- }
-
- // Parse the short description
- while ( ( $line = array_shift( $contents ) ) !== null ) {
- $trimmed = trim( $line );
- if ( empty( $trimmed ) ) {
- $this->short_description .= "\n";
- continue;
- }
- if ( ( '=' === $trimmed[0] && isset( $trimmed[1] ) && '=' === $trimmed[1] ) ||
- ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] ) ) { // Stop after any Markdown heading
- array_unshift( $contents, $line );
- break;
- }
-
- $this->short_description .= $line . "\n";
- }
- $this->short_description = trim( $this->short_description );
-
- // Parse the rest of the body
- // Prefill the sections, we'll filter out empty sections later.
- $this->sections = array_fill_keys( $this->expected_sections, '' );
- $current = $section_name = $section_title = '';
- while ( ( $line = array_shift( $contents ) ) !== null ) {
- $trimmed = trim( $line );
- if ( empty( $trimmed ) ) {
- $current .= "\n";
- continue;
- }
-
- if ( ( '=' === $trimmed[0] && isset( $trimmed[1] ) && '=' === $trimmed[1] ) ||
- ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] && isset( $trimmed[2] ) && '#' !== $trimmed[2] ) ) { // Stop only after a ## Markdown header, not a ###.
- if ( ! empty( $section_name ) ) {
- $this->sections[ $section_name ] .= trim( $current );
- }
-
- $current = '';
- $section_title = trim( $line, "#= \t" );
- $section_name = strtolower( str_replace( ' ', '_', $section_title ) );
-
- if ( isset( $this->alias_sections[ $section_name ] ) ) {
- $section_name = $this->alias_sections[ $section_name ];
- }
-
- // If we encounter an unknown section header, include the provided Title, we'll filter it to other_notes later.
- if ( ! in_array( $section_name, $this->expected_sections ) ) {
- $current .= '<h3>' . $section_title . '</h3>';
- $section_name = 'other_notes';
- }
- continue;
- }
-
- $current .= $line . "\n";
- }
-
- if ( ! empty( $section_name ) ) {
- $this->sections[ $section_name ] .= trim( $current );
- }
-
- // Filter out any empty sections.
- $this->sections = array_filter( $this->sections );
-
- // Use the first line of the description for the short description if not provided.
- if ( empty( $this->short_description ) && ! empty( $this->sections['description'] ) ) {
- $this->short_description = array_filter( explode( "\n", $this->sections['description'] ) )[0];
- }
-
- // Use the short description for the description section if not provided.
- if ( empty( $this->sections['description'] ) ) {
- $this->sections['description'] = $this->short_description;
- }
-
- // Parse out the Upgrade Notice section into it's own data
- if ( isset( $this->sections['upgrade_notice'] ) ) {
- $lines = explode( "\n", $this->sections['upgrade_notice'] );
- $version = null;
- $current = '';
- while ( ( $line = array_shift( $lines ) ) !== null ) {
- $trimmed = trim( $line );
- if ( empty( $trimmed ) ) {
- continue;
- }
-
- if ( '=' === $trimmed[0] || '#' === $trimmed[0] ) {
- if ( ! empty( $current ) ) {
- $this->upgrade_notice[ $version ] = $this->sanitize_text( trim( $current ) );
- }
-
- $current = '';
- $version = trim( $line, "#= \t" );
- continue;
- }
-
- $current .= $line . "\n";
- }
- if ( ! empty( $version ) && ! empty( $current ) ) {
- $this->upgrade_notice[ $version ] = $this->sanitize_text( trim( $current ) );
- }
- unset( $this->sections['upgrade_notice'] );
- }
-
- // Markdownify!
- $this->sections = array_map( array( $this, 'parse_markdown' ), $this->sections );
- $this->upgrade_notice = array_map( array( $this, 'parse_markdown' ), $this->upgrade_notice );
-
- // Sanitize and trim the short_description to match requirements
- $this->short_description = $this->sanitize_text( $this->short_description );
- $this->short_description = $this->trim_length( $this->short_description, 150 );
- $this->short_description = $this->parse_markdown( $this->short_description );
- $this->short_description = wp_strip_all_tags( $this->short_description );
-
- if ( isset( $this->sections['screenshots'] ) ) {
- preg_match_all( '#<li>(.*?)</li>#is', $this->sections['screenshots'], $screenshots, PREG_SET_ORDER );
- if ( $screenshots ) {
- $i = 1; // Screenshots start from 1
- foreach ( $screenshots as $ss ) {
- $this->screenshots[ $i++ ] = $this->filter_text( $ss[1] );
- }
- }
- unset( $this->sections['screenshots'] );
- }
-
- // Filter the HTML
- $this->sections = array_map( array( $this, 'filter_text' ), $this->sections );
-
- return true;
- }
-
- protected function get_first_nonwhitespace( &$contents ) {
- while ( ( $line = array_shift( $contents ) ) !== null ) {
- $trimmed = trim( $line );
- if ( ! empty( $trimmed ) ) {
- break;
- }
- }
-
- return $line;
- }
-
- protected function strip_newlines( $line ) {
- return rtrim( $line, "\r\n" );
- }
-
- protected function trim_length( $desc, $length = 150 ) {
- if ( mb_strlen( $desc ) > $length ) {
- $desc = mb_substr( $desc, 0, $length ) . ' …';
-
- // If not a full sentence, and one ends within 20% of the end, trim it to that.
- if ( '.' !== mb_substr( $desc, -1 ) && ( $pos = mb_strrpos( $desc, '.' ) ) > ( 0.8 * $length ) ) {
- $desc = mb_substr( $desc, 0, $pos + 1 );
- }
- }
-
- return trim( $desc );
- }
-
- /**
- * @access protected
- *
- * @param string $text
- * @return string
- */
- protected function filter_text( $text ) {
- $text = trim( $text );
-
- $allowed = array(
- 'a' => array(
- 'href' => true,
- 'title' => true,
- 'rel' => true,
- ),
- 'blockquote' => array(
- 'cite' => true
- ),
- 'br' => true,
- 'p' => true,
- 'code' => true,
- 'pre' => true,
- 'em' => true,
- 'strong' => true,
- 'ul' => true,
- 'ol' => true,
- 'li' => true,
- 'h3' => true,
- 'h4' => true,
- );
-
- $text = force_balance_tags( $text );
- // TODO: make_clickable() will act inside shortcodes.
- //$text = make_clickable( $text );
-
- $text = wp_kses( $text, $allowed );
-
- // wpautop() will eventually replace all \n's with <br>s, and that isn't what we want.
- $text = preg_replace( "/(?<![> ])\n/", ' ', $text );
-
- $text = trim( $text );
-
- return $text;
- }
-
- /**
- * @access protected
- *
- * @param string $text
- * @return string
- */
- protected function sanitize_text( $text ) { // not fancy
- $text = strip_tags( $text );
- $text = esc_html( $text );
- $text = trim( $text );
-
- return $text;
- }
-
- /**
- * Sanitize provided contributors to valid WordPress users
- *
- * @param array $users Array of user_login's or user_nicename's.
- * @return array Array of user_logins.
- */
- protected function sanitize_contributors( $users ) {
- foreach ( $users as $i => $name ) {
- if ( $user = get_user_by( 'login', $name ) ) {
- // Check the case of the user login matches.
- if ( $name !== $user->user_login ) {
- $users[ $i ] = $user->user_login;
- }
- } elseif ( false !== ( $user = get_user_by( 'slug', $name ) ) ) {
- // Overwrite the nicename with the user_login
- $users[ $i ] = $user->user_login;
- } else {
- // Unknown user, we'll skip these entirely to encourage correct readmes
- unset( $users[ $i ] );
- }
- }
- return $users;
- }
-
- /**
- * Sanitize the provided stable tag to something we expect.
- *
- * @param string $stable_tag the raw Stable Tag line from the readme.
- * @return string The sanitized $stable_tag.
- */
- protected function sanitize_stable_tag( $stable_tag ) {
- $stable_tag = trim( $stable_tag );
- $stable_tag = trim( $stable_tag, '"\'' ); // "trunk"
- $stable_tag = preg_replace( '!^/?tags/!i', '', $stable_tag ); // "tags/1.2.3"
- $stable_tag = preg_replace( '![^a-z0-9_.-]!i', '', $stable_tag );
-
- // If the stable_tag begins with a ., we treat it as 0.blah
- if ( '.' == substr( $stable_tag, 0, 1 ) ) {
- $stable_tag = "0{$stable_tag}";
- }
-
- return $stable_tag;
- }
-
- protected function parse_markdown( $text ) {
- static $markdown = null;
- if ( is_null( $markdown ) ) {
- $markdown = new Markdown();
- }
-
- return $markdown->transform( $text );
- }
-
-}
</del></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php 2016-06-19 19:34:19 UTC (rev 3476)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php 2016-06-19 20:40:01 UTC (rev 3477)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,7 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\CLI;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Plugin_Directory;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-use WordPressdotorg\Plugin_Directory\Readme_Parser;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Plugin_Directory\Readme\Parser;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Template;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Tools;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -300,7 +300,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $trunk_readme_file = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk/{$trunk_readme_file}";
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $trunk_readme = new Readme_Parser( $trunk_readme_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $trunk_readme = new Parser( $trunk_readme_file );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $stable_tag = $trunk_readme->stable_tag;
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -354,7 +354,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // The readme may not actually exist, but that's okay.
</span><span class="cx" style="display: block; padding: 0 10px"> $readme = $this->find_readme_file( $tmp_dir . '/export' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $readme = new Readme_Parser( $readme );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $readme = new Parser( $readme );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // There must be valid plugin headers though.
</span><span class="cx" style="display: block; padding: 0 10px"> $plugin_headers = $this->find_plugin_headers( "$tmp_dir/export" );
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryreadmeclassparserphpfromrev3476sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassreadmeparserphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php (from rev 3476, sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php 2016-06-19 20:40:01 UTC (rev 3477)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,510 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Readme;
+use WordPressdotorg\Plugin_Directory\Markdown;
+
+/**
+ * WordPress.org Plugin Readme Parser.
+ *
+ * Based on Baikonur_ReadmeParser from https://github.com/rmccue/WordPress-Readme-Parser
+ *
+ * @package WordPressdotorg\Plugin_Directory\Readme
+ */
+class Parser {
+
+ /**
+ * @var string
+ */
+ public $name = '';
+
+ /**
+ * @var array
+ */
+ public $tags = array();
+
+ /**
+ * @var string
+ */
+ public $requires = '';
+
+ /**
+ * @var string
+ */
+ public $tested = '';
+
+ /**
+ * @var array
+ */
+ public $contributors = array();
+
+ /**
+ * @var string
+ */
+ public $stable_tag = '';
+
+ /**
+ * @var string
+ */
+ public $donate_link = '';
+
+ /**
+ * @var string
+ */
+ public $short_description = '';
+
+ /**
+ * @var array
+ */
+ public $sections = array();
+
+ /**
+ * @var array
+ */
+ public $upgrade_notice = array();
+
+ /**
+ * @var array
+ */
+ public $screenshots = array();
+
+ /**
+ * These are the readme sections that we expect.
+ *
+ * @var array
+ */
+ private $expected_sections = array(
+ 'description',
+ 'installation',
+ 'faq',
+ 'screenshots',
+ 'changelog',
+ 'upgrade_notice',
+ 'other_notes',
+ );
+
+ /**
+ * We alias these sections, from => to
+ *
+ * @var array
+ */
+ private $alias_sections = array(
+ 'frequently_asked_questions' => 'faq',
+ 'change_log' => 'changelog',
+ 'screenshot' => 'screenshots',
+ );
+
+ /**
+ * These are the valid header mappings for the header.
+ *
+ * @var array
+ */
+ private $valid_headers = array(
+ 'tested' => 'tested',
+ 'tested up to' => 'tested',
+ 'requires' => 'requires',
+ 'requires at least' => 'requires',
+ 'tags' => 'tags',
+ 'contributors' => 'contributors',
+ 'donate link' => 'donate_link',
+ 'stable tag' => 'stable_tag',
+ );
+
+ /**
+ * Parser constructor.
+ *
+ * @param string $file
+ */
+ public function __construct( $file ) {
+ if ( $file ) {
+ $this->parse_readme( $file );
+ }
+ }
+
+ /**
+ * @param string $file
+ * @return bool
+ */
+ protected function parse_readme( $file ) {
+ $contents = file_get_contents( $file );
+ $contents = preg_split( '!\R!', $contents );
+ $contents = array_map( array( $this, 'strip_newlines' ), $contents );
+
+ // Strip UTF8 BOM if present.
+ if ( 0 === strpos( $contents[0], "\xEF\xBB\xBF" ) ) {
+ $contents[0] = substr( $contents[0], 3 );
+ }
+
+ // Convert UTF-16 files.
+ if ( 0 === strpos( $contents[0], "\xFF\xFE" ) ) {
+ foreach ( $contents as $i => $line ) {
+ $contents[ $i ] = mb_convert_encoding( $line, 'UTF-8', 'UTF-16' );
+ }
+ }
+
+ $line = $this->get_first_nonwhitespace( $contents );
+ $this->name = $this->sanitize_text( trim( $line, "#= \t\0\x0B" ) );
+
+ // Strip Github style header\n==== underlines.
+ if ( ! empty( $contents ) && '' === trim( $contents[0], '=-' ) ) {
+ array_shift( $contents );
+ }
+
+ // Handle readme's which do `=== Plugin Name ===\nMy SuperAwesomePlugin Name\n...`
+ if ( 'plugin name' == strtolower( $this->name ) ) {
+ $this->name = $line = $this->get_first_nonwhitespace( $contents );
+
+ // Ensure that the line read wasn't an actual header or description.
+ if ( strlen( $line ) > 50 || preg_match( '~^(' . implode( '|', array_keys( $this->valid_headers ) ) . ')\s*:~i', $line ) ) {
+ $this->name = false;
+ array_unshift( $contents, $line );
+ }
+ }
+
+ // Parse headers.
+ $headers = array();
+
+ $line = $this->get_first_nonwhitespace( $contents );
+ do {
+ $value = null;
+ if ( false === strpos( $line, ':' ) ) {
+
+ // Some plugins have line-breaks within the headers.
+ if ( ! empty( $line ) ) {
+ break;
+ } else {
+ continue;
+ }
+ }
+
+ $bits = explode( ':', trim( $line ), 2 );
+ list( $key, $value ) = $bits;
+ $key = strtolower( trim( $key, " \t*-\r\n" ) );
+ if ( isset( $this->valid_headers[ $key ] ) ) {
+ $headers[ $this->valid_headers[ $key ] ] = trim( $value );
+ }
+ } while ( ( $line = array_shift( $contents ) ) !== null );
+ array_unshift( $contents, $line );
+
+ if ( ! empty( $headers['tags'] ) ) {
+ $this->tags = explode( ',', $headers['tags'] );
+ $this->tags = array_map( 'trim', $this->tags );
+ }
+ if ( ! empty( $headers['requires'] ) ) {
+ $this->requires = $headers['requires'];
+ }
+ if ( ! empty( $headers['tested'] ) ) {
+ $this->tested = $headers['tested'];
+ }
+ if ( ! empty( $headers['contributors'] ) ) {
+ $this->contributors = explode( ',', $headers['contributors'] );
+ $this->contributors = array_map( 'trim', $this->contributors );
+ $this->contributors = $this->sanitize_contributors( $this->contributors );
+ }
+ if ( ! empty( $headers['stable_tag'] ) ) {
+ $this->stable_tag = $this->sanitize_stable_tag( $headers['stable_tag'] );
+ }
+ if ( ! empty( $headers['donate_link'] ) ) {
+ $this->donate_link = $headers['donate_link'];
+ }
+
+ // Parse the short description.
+ while ( ( $line = array_shift( $contents ) ) !== null ) {
+ $trimmed = trim( $line );
+ if ( empty( $trimmed ) ) {
+ $this->short_description .= "\n";
+ continue;
+ }
+ if ( ( '=' === $trimmed[0] && isset( $trimmed[1] ) && '=' === $trimmed[1] ) ||
+ ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] )
+ ) {
+
+ // Stop after any Markdown heading.
+ array_unshift( $contents, $line );
+ break;
+ }
+
+ $this->short_description .= $line . "\n";
+ }
+ $this->short_description = trim( $this->short_description );
+
+ /*
+ * Parse the rest of the body.
+ * Pre-fill the sections, we'll filter out empty sections later.
+ */
+ $this->sections = array_fill_keys( $this->expected_sections, '' );
+ $current = $section_name = $section_title = '';
+ while ( ( $line = array_shift( $contents ) ) !== null ) {
+ $trimmed = trim( $line );
+ if ( empty( $trimmed ) ) {
+ $current .= "\n";
+ continue;
+ }
+
+ // Stop only after a ## Markdown header, not a ###.
+ if ( ( '=' === $trimmed[0] && isset( $trimmed[1] ) && '=' === $trimmed[1] ) ||
+ ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] && isset( $trimmed[2] ) && '#' !== $trimmed[2] )
+ ) {
+
+ if ( ! empty( $section_name ) ) {
+ $this->sections[ $section_name ] .= trim( $current );
+ }
+
+ $current = '';
+ $section_title = trim( $line, "#= \t" );
+ $section_name = strtolower( str_replace( ' ', '_', $section_title ) );
+
+ if ( isset( $this->alias_sections[ $section_name ] ) ) {
+ $section_name = $this->alias_sections[ $section_name ];
+ }
+
+ // If we encounter an unknown section header, include the provided Title, we'll filter it to other_notes later.
+ if ( ! in_array( $section_name, $this->expected_sections ) ) {
+ $current .= '<h3>' . $section_title . '</h3>';
+ $section_name = 'other_notes';
+ }
+ continue;
+ }
+
+ $current .= $line . "\n";
+ }
+
+ if ( ! empty( $section_name ) ) {
+ $this->sections[ $section_name ] .= trim( $current );
+ }
+
+ // Filter out any empty sections.
+ $this->sections = array_filter( $this->sections );
+
+ // Use the first line of the description for the short description if not provided.
+ if ( empty( $this->short_description ) && ! empty( $this->sections['description'] ) ) {
+ $this->short_description = array_filter( explode( "\n", $this->sections['description'] ) )[0];
+ }
+
+ // Use the short description for the description section if not provided.
+ if ( empty( $this->sections['description'] ) ) {
+ $this->sections['description'] = $this->short_description;
+ }
+
+ // Parse out the Upgrade Notice section into it's own data.
+ if ( isset( $this->sections['upgrade_notice'] ) ) {
+ $lines = explode( "\n", $this->sections['upgrade_notice'] );
+ $version = null;
+ $current = '';
+ while ( ( $line = array_shift( $lines ) ) !== null ) {
+ $trimmed = trim( $line );
+ if ( empty( $trimmed ) ) {
+ continue;
+ }
+
+ if ( '=' === $trimmed[0] || '#' === $trimmed[0] ) {
+ if ( ! empty( $current ) ) {
+ $this->upgrade_notice[ $version ] = $this->sanitize_text( trim( $current ) );
+ }
+
+ $current = '';
+ $version = trim( $line, "#= \t" );
+ continue;
+ }
+
+ $current .= $line . "\n";
+ }
+ if ( ! empty( $version ) && ! empty( $current ) ) {
+ $this->upgrade_notice[ $version ] = $this->sanitize_text( trim( $current ) );
+ }
+ unset( $this->sections['upgrade_notice'] );
+ }
+
+ // Markdownify!
+ $this->sections = array_map( array( $this, 'parse_markdown' ), $this->sections );
+ $this->upgrade_notice = array_map( array( $this, 'parse_markdown' ), $this->upgrade_notice );
+
+ // Sanitize and trim the short_description to match requirements.
+ $this->short_description = $this->sanitize_text( $this->short_description );
+ $this->short_description = $this->trim_length( $this->short_description, 150 );
+ $this->short_description = $this->parse_markdown( $this->short_description );
+ $this->short_description = wp_strip_all_tags( $this->short_description );
+
+ if ( isset( $this->sections['screenshots'] ) ) {
+ preg_match_all( '#<li>(.*?)</li>#is', $this->sections['screenshots'], $screenshots, PREG_SET_ORDER );
+ if ( $screenshots ) {
+ $i = 1; // Screenshots start from 1.
+ foreach ( $screenshots as $ss ) {
+ $this->screenshots[ $i++ ] = $this->filter_text( $ss[1] );
+ }
+ }
+ unset( $this->sections['screenshots'] );
+ }
+
+ // Filter the HTML.
+ $this->sections = array_map( array( $this, 'filter_text' ), $this->sections );
+
+ return true;
+ }
+
+ /**
+ * @access protected
+ *
+ * @param string $contents
+ * @return string
+ */
+ protected function get_first_nonwhitespace( &$contents ) {
+ while ( ( $line = array_shift( $contents ) ) !== null ) {
+ $trimmed = trim( $line );
+ if ( ! empty( $trimmed ) ) {
+ break;
+ }
+ }
+
+ return $line;
+ }
+
+ /**
+ * @access protected
+ *
+ * @param string $line
+ * @return string
+ */
+ protected function strip_newlines( $line ) {
+ return rtrim( $line, "\r\n" );
+ }
+
+ /**
+ * @access protected
+ *
+ * @param string $desc
+ * @param int $length
+ * @return string
+ */
+ protected function trim_length( $desc, $length = 150 ) {
+ if ( mb_strlen( $desc ) > $length ) {
+ $desc = mb_substr( $desc, 0, $length ) . ' …';
+
+ // If not a full sentence, and one ends within 20% of the end, trim it to that.
+ if ( '.' !== mb_substr( $desc, -1 ) && ( $pos = mb_strrpos( $desc, '.' ) ) > ( 0.8 * $length ) ) {
+ $desc = mb_substr( $desc, 0, $pos + 1 );
+ }
+ }
+
+ return trim( $desc );
+ }
+
+ /**
+ * @access protected
+ *
+ * @param string $text
+ * @return string
+ */
+ protected function filter_text( $text ) {
+ $text = trim( $text );
+
+ $allowed = array(
+ 'a' => array(
+ 'href' => true,
+ 'title' => true,
+ 'rel' => true,
+ ),
+ 'blockquote' => array(
+ 'cite' => true
+ ),
+ 'br' => true,
+ 'p' => true,
+ 'code' => true,
+ 'pre' => true,
+ 'em' => true,
+ 'strong' => true,
+ 'ul' => true,
+ 'ol' => true,
+ 'li' => true,
+ 'h3' => true,
+ 'h4' => true,
+ );
+
+ $text = force_balance_tags( $text );
+ // TODO: make_clickable() will act inside shortcodes.
+ //$text = make_clickable( $text );
+
+ $text = wp_kses( $text, $allowed );
+
+ // wpautop() will eventually replace all \n's with <br>s, and that isn't what we want.
+ $text = preg_replace( "/(?<![> ])\n/", ' ', $text );
+
+ $text = trim( $text );
+
+ return $text;
+ }
+
+ /**
+ * @access protected
+ *
+ * @param string $text
+ * @return string
+ */
+ protected function sanitize_text( $text ) { // not fancy
+ $text = strip_tags( $text );
+ $text = esc_html( $text );
+ $text = trim( $text );
+
+ return $text;
+ }
+
+ /**
+ * Sanitize provided contributors to valid WordPress users
+ *
+ * @param array $users Array of user_login's or user_nicename's.
+ * @return array Array of user_logins.
+ */
+ protected function sanitize_contributors( $users ) {
+ foreach ( $users as $i => $name ) {
+ if ( $user = get_user_by( 'login', $name ) ) {
+
+ // Check the case of the user login matches.
+ if ( $name !== $user->user_login ) {
+ $users[ $i ] = $user->user_login;
+ }
+ } elseif ( false !== ( $user = get_user_by( 'slug', $name ) ) ) {
+
+ // Overwrite the nicename with the user_login.
+ $users[ $i ] = $user->user_login;
+ } else {
+
+ // Unknown user, we'll skip these entirely to encourage correct readme files.
+ unset( $users[ $i ] );
+ }
+ }
+
+ return $users;
+ }
+
+ /**
+ * Sanitize the provided stable tag to something we expect.
+ *
+ * @param string $stable_tag the raw Stable Tag line from the readme.
+ * @return string The sanitized $stable_tag.
+ */
+ protected function sanitize_stable_tag( $stable_tag ) {
+ $stable_tag = trim( $stable_tag );
+ $stable_tag = trim( $stable_tag, '"\'' ); // "trunk"
+ $stable_tag = preg_replace( '!^/?tags/!i', '', $stable_tag ); // "tags/1.2.3"
+ $stable_tag = preg_replace( '![^a-z0-9_.-]!i', '', $stable_tag );
+
+ // If the stable_tag begins with a ., we treat it as 0.blah.
+ if ( '.' == substr( $stable_tag, 0, 1 ) ) {
+ $stable_tag = "0{$stable_tag}";
+ }
+
+ return $stable_tag;
+ }
+
+ /**
+ * @param string $text
+ * @return string
+ */
+ protected function parse_markdown( $text ) {
+ static $markdown = null;
+
+ if ( is_null( $markdown ) ) {
+ $markdown = new Markdown();
+ }
+
+ return $markdown->transform( $text );
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryreadmeclassvalidatorphpfromrev3476sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclassreadmevalidatorphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php (from rev 3476, sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-readme-validator.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php 2016-06-19 20:40:01 UTC (rev 3477)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,206 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Readme;
+use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
+
+/**
+ * A wp-admin interface to validate readme files.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Readme
+ */
+class Validator {
+
+ /**
+ * Fetch the instance of the Validator class.
+ *
+ * @static
+ */
+ public static function instance() {
+ static $instance = null;
+
+ return ! is_null( $instance ) ? $instance : $instance = new Validator();
+ }
+
+ /**
+ * Validator constructor.
+ */
+ private function __construct() {
+ add_action( 'plugin_page_readme_validator', array( $this, 'add_form_fields' ) );
+ add_action( 'plugin_page_readme_validator', array( $this, 'validate' ) );
+ }
+
+ /**
+ * Displays a for to validate readme.txt files and blobs of text.
+ */
+ public function display() {
+ ?>
+ <div class="wrap">
+ <h2><?php _e( 'WordPress Plugin readme.txt Validator', 'wporg-plugins' ); ?></h2>
+ <?php settings_errors( 'wporg-plugins-readme' ); ?>
+ <form method="post" action="<?php echo esc_url( add_query_arg( array( 'post_type' => 'plugin', 'page' => 'readme_validator' ), admin_url( 'edit.php' ) ) ); ?>">
+ <?php
+ wp_nonce_field( 'validate-readme' );
+ do_settings_sections( 'readme_validator' );
+ submit_button( __( 'Validate', 'wporg-plugins' ) );
+ ?>
+ </form>
+ </div>
+ <?php
+ }
+
+ /**
+ * Registers form fields for this admin page.
+ */
+ public function add_form_fields() {
+ add_settings_section( 'default', '', array( $this, 'section_description' ), 'readme_validator' );
+
+ add_settings_field( 'readme_url', __( 'URL to readme.txt file', 'wporg-plugins' ), array( $this, 'url_input' ), 'readme_validator', 'default', array(
+ 'label_for' => 'readme_url',
+ ) );
+ add_settings_field( 'readme_text', __( 'Text of readme.txt', 'wporg-plugins' ), array( $this, 'textarea' ), 'readme_validator', 'default', array(
+ 'label_for' => 'readme_contents',
+ ) );
+ }
+
+ /**
+ * Validates readme.txt contents and adds feedback.
+ */
+ public function validate() {
+ if ( ! isset( $_REQUEST['_wpnonce'] ) ) {
+ return;
+ }
+ check_admin_referer( 'validate-readme' );
+
+ $readme = '';
+ $temp_file = Filesystem::temp_directory() . '/readme.txt';
+ $warnings = array();
+ $notes = array();
+
+ if ( ! empty( $_REQUEST['readme_url'] ) ) {
+ $url = esc_url_raw( $_REQUEST['readme_url'] );
+
+ if ( strtolower( substr( $url, -10 ) ) != 'readme.txt' ) {
+ /* Translators: File name; */
+ add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( 'URL must end in %s!', 'wporg-plugins' ), '<code>readme.txt</code>' ) );
+ return;
+ }
+
+ if ( ! $readme = @file_get_contents( $url ) ) {
+ add_settings_error( 'wporg-plugins-readme', 'readme-validator', __( 'Invalid readme.txt URL.', 'wporg-plugins' ) );
+ return;
+ }
+
+ } elseif ( ! empty( $_REQUEST['readme_contents'] ) && is_string( $_REQUEST['readme_contents'] ) ) {
+ $readme = wp_unslash( $_REQUEST['readme_contents'] );
+ }
+
+ if ( empty( $readme ) ) {
+ return;
+ }
+
+ file_put_contents( $temp_file, $readme );
+ $readme = new Parser( $temp_file );
+
+ // Fatal errors.
+ if ( empty( $readme->name ) ) {
+ /* Translators: Plugin header tag; */
+ add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( "Fatal Error:\nNo plugin name detected. Plugin names look like: %s", 'wporg-plugins' ), '<code>=== Plugin Name ===</code>' ) );
+ return;
+ }
+
+ // Warnings.
+ if ( empty( $readme->requires ) ) {
+ /* Translators: Plugin header tag; */
+ $warnings[] = sprintf( __( '%s is missing.', 'wporg-plugins' ), '<code>Requires at least</code>' );
+ }
+ if ( empty( $readme->tested ) ) {
+ /* Translators: Plugin header tag; */
+ $warnings[] = sprintf( __( '%s is missing.', 'wporg-plugins' ), '<code>Tested up to</code>' );
+ }
+ if ( empty( $readme->stable_tag ) ) {
+ /* Translators: 1: Plugin header tag; 2: SVN directory; 3: Plugin header tag; */
+ $warnings[] = sprintf( __( '%1$s is missing. Hint: If you treat %2$s as stable, put %3$s.', 'wporg-plugins' ), '<code>Stable tag</code>', '<code>/trunk/</code>', '<code>Stable tag: trunk</code>' );
+ }
+ if ( ! count( $readme->contributors ) ) {
+ /* Translators: Plugin header tag; */
+ $warnings[] = sprintf( __( 'No %s listed.', 'wporg-plugins' ), '<code>Contributors</code>' );
+ }
+
+ if ( $warnings ) {
+ $message = __( 'Warnings:', 'wporg-plugins' ) . "\n<ul class='warning error'>\n";
+ foreach ( $warnings as $warning ) {
+ $message .= "<li>$warning</li>\n";
+ }
+ $message .= "</ul>\n</div>";
+
+ add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-warning' );
+ return;
+ }
+
+ // Notes.
+ if ( empty( $readme->sections['faq'] ) ) {
+ /* Translators: Plugin header tag; */
+ $notes[] = sprintf( __( 'No %s section was found', 'wporg-plugins' ), '<code>== Frequently Asked Questions ==</code>' );
+ }
+ if ( empty( $readme->sections['changelog'] ) ) {
+ /* Translators: Plugin header tag; */
+ $notes[] = sprintf( __( 'No %s section was found', 'wporg-plugins' ), '<code>== Changelog ==</code>' );
+ }
+ if ( empty( $readme->upgrade_notice ) ) {
+ /* Translators: Plugin header tag; */
+ $notes[] = sprintf( __( 'No %s section was found', 'wporg-plugins' ), '<code>== Upgrade Notice ==</code>' );
+ }
+ if ( empty( $readme->screenshots ) ) {
+ /* Translators: Plugin header tag; */
+ $notes[] = sprintf( __( 'No %s section was found', 'wporg-plugins' ), '<code>== Screenshots ==</code>' );
+ }
+ if ( empty( $readme->donate_link ) ) {
+ $notes[] = __( 'No donate link was found', 'wporg-plugins' );
+ }
+
+ if ( $notes ) {
+ $message = __( 'Notes:' ) . "\n<ul class='note error'>\n";
+ foreach ( $notes as $note ) {
+ $message .= "<li>$note</li>\n";
+ }
+ $message .= "</ul>\n</div>";
+
+ add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-info' );
+ return;
+ }
+
+ /* Translators: File name; */
+ add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( 'Your %s rocks. Seriously. Flying colors.', 'wporg-plugins' ), '<code>readme.txt</code>' ), 'updated' );
+ }
+
+ /**
+ * Help text for the form following after it.
+ */
+ public function section_description() {
+ /* Translators: File name; */
+ echo '<p>' . sprintf( __( 'Enter the URL to your %s file or paste its content below.' ), '<code>readme.txt</code>' ) . '</p>';
+ }
+
+ /**
+ * Displays an input field for the readme.txt URL.
+ */
+ public function url_input() {
+ $url = empty( $_REQUEST['readme_url'] ) ? '' : $_REQUEST['readme_url'];
+ ?>
+ <label>
+ <input type="url" id="readme_url" name="readme_url" size="70" value="<?php echo esc_url( $url ); ?>" />
+ </label>
+ <?php
+ }
+
+ /**
+ * Displays a textarea for readme.txt blobs.
+ */
+ public function textarea() {
+ $text = empty( $_REQUEST['readme_contents'] ) ? '' : wp_unslash( $_REQUEST['readme_contents'] );
+ ?>
+ <label>
+ <textarea type="text" id="readme_contents" class="large-text" name="readme_contents" cols="50" rows="10"><?php echo esc_textarea( $text ); ?></textarea>
+ </label>
+ <?php
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryshortcodesclassuploadhandlerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php 2016-06-19 19:34:19 UTC (rev 3476)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php 2016-06-19 20:40:01 UTC (rev 3477)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\Shortcodes;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-use WordPressdotorg\Plugin_Directory\Readme_Parser;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Plugin_Directory\Readme\Parser;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Plugin_Directory;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -143,7 +143,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '<code>readme.md</code>'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $readme = new Readme_Parser( $readme );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $readme = new Parser( $readme );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Pass it through Plugin Check and see how great this plugin really is.
</span><span class="cx" style="display: block; padding: 0 10px"> $result = $this->check_plugin();
</span></span></pre>
</div>
</div>
</body>
</html>