<!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>[4261] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Readme Validator: Strip out the `wp-admin` handling in the readme handler and streamline the error checks a little.</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/4261">4261</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/4261","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-10-19 03:27:01 +0000 (Wed, 19 Oct 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: Readme Validator: Strip out the `wp-admin` handling in the readme handler and streamline the error checks a little.
See <a href="http://meta.trac.wordpress.org/ticket/2128">#2128</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryreadmeclassvalidatorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryshortcodesclassreadmevalidatorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-readme-validator.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryreadmeclassvalidatorphp"></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/readme/class-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 2016-10-19 02:30:54 UTC (rev 4260)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php 2016-10-19 03:27:01 UTC (rev 4261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -21,101 +21,49 @@
</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"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Validator constructor.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Validates a readme by URL.
+ *
+ * @param string $url The URL of the readme to validate.
+ * @return array Array of the readme validation results.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private function __construct() {
- add_action( 'plugin_page_readme_validator', array( $this, 'add_form_fields' ) );
- add_action( 'plugin_page_readme_validator', array( $this, 'validate' ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function validate_url( $url ) {
+ $url = esc_url_raw( $url );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * 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;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( strtolower( substr( $url, -10 ) ) != 'readme.txt' ) {
+ /* Translators: File name; */
+ $error = sprintf( __( 'URL must end in %s!', 'wporg-plugins' ), '<code>readme.txt</code>' );
+ return array(
+ 'errors' => array( $error )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- check_admin_referer( 'validate-readme' );
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $readme = '';
-
- 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'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $readme = wp_safe_remote_get( $url );
+ if ( ! $readme_text = wp_remote_retrieve_body( $readme ) ) {
+ $error = __( 'Invalid readme.txt URL.', 'wporg-plugins' );
+ return array(
+ 'errors' => array( $error )
+ );
</ins><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">- if ( empty( $readme ) ) {
- return;
- }
-
- return $this->validate_content( $readme );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $this->validate_content( $readme_text );
</ins><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"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Validates content via a string paramater and adds feedback.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Validates readme contents by string.
+ *
+ * @param string $readme The text of the readme.
+ * @return array Array of the readme validation results.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function validate_content( $readme ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $temp_file = Filesystem::temp_directory() . '/readme.txt';
- $errors = array();
- $warnings = array();
- $notes = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $readme = new Parser( 'data:text/plain,' . urlencode( $readme ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- file_put_contents( $temp_file, $readme );
- $readme = new Parser( $temp_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $errors = $warnings = $notes = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Fatal errors.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $readme->name ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> /* Translators: Plugin header tag; */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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>' ) );
- $errors[] = array( 'error', sprintf( __( "Fatal Error:\nNo plugin name detected. Plugin names look like: %s", 'wporg-plugins' ), '<code>=== Plugin Name ===</code>' ) );
- return $errors;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $errors[] = sprintf( __( "No plugin name detected. Plugin names look like: %s", 'wporg-plugins' ), '<code>=== Plugin Name ===</code>' );
</ins><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"> // Warnings.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -136,19 +84,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $warnings[] = sprintf( __( 'No %s listed.', 'wporg-plugins' ), '<code>Contributors</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">- 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>";
-
- if ( function_exists( 'add_settings_error' ) ) {
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-warning' );
- }
- return $message;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Notes.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $readme->sections['faq'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> /* Translators: Plugin header tag; */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -170,55 +105,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $notes[] = __( 'No donate link was found', 'wporg-plugins' );
</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">- if ( $notes ) {
- $message = __( 'Notes:' ) . "\n<ul class='note error'>\n";
- foreach ( $notes as $note ) {
- $message .= "<li>$note</li>\n";
- }
- $message .= "</ul>\n</div>";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return compact( 'errors', 'warnings', 'notes' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( function_exists( 'add_settings_error' ) ) {
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-info' );
- }
- return $message;
- }
-
- /* Translators: File name; */
- if ( function_exists( 'add_settings_error' ) ) {
- add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( 'Your %s rocks. Seriously. Flying colors.', 'wporg-plugins' ), '<code>readme.txt</code>' ), 'updated' );
- }
</del><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">-
- /**
- * 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 class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryshortcodesclassreadmevalidatorphp"></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-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/shortcodes/class-readme-validator.php 2016-10-19 02:30:54 UTC (rev 4260)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-readme-validator.php 2016-10-19 03:27:01 UTC (rev 4261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,64 +4,35 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> class Readme_Validator {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private $errors = array();
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 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();
- }
-
- private function __construct() {
- }
-
- private function display_errors( $errors ) {
- if ( is_array( $errors ) && !empty( $errors ) ) {
- $message = __( 'Warnings:', 'wporg-plugins' ) . "\n<ul class='warning error'>\n";
- foreach ( $errors as $error ) {
- $message .= "<li>" . esc_html($error) . "</li>\n";
- }
- $message .= "</ul>\n</div>";
-
- echo $message;
- }
-
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * Displays a form to validate readme.txt files and blobs of text.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function display() {
-
- $message = null;
- if ( !empty( $_POST ) ) {
- $message = self::validate();
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function display() {
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="wrap">
</span><span class="cx" style="display: block; padding: 0 10px"> <h2><?php _e( 'WordPress Plugin readme.txt Validator', 'wporg-plugins' ); ?></h2>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php if ( $message ) echo $message; ?>
- <form method="post" action="<?php echo esc_url( add_query_arg( array() ) ); ?>">
- <input type="hidden" name="url" value="1" />
- <p>http://<input type="text" name="readme_url" size="70" /> <input type="submit" value="Validate!" /></p>
- <?php
- wp_nonce_field( 'validate-readme-url' );
- ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ <?php
+ if ( $_POST ) {
+ self::validate_readme();
+ }
+ ?>
+
+ <form method="post" action="">
+ <p>
+ <input type="text" name="readme_url" size="70" placeholder="https://" value="<?php if ( isset( $_GET['readme_url'] ) ) { echo esc_attr( $_POST['readme_url'] ); } ?>" />
+ <input type="submit" value="<?php esc_attr_e( 'Validate!', 'wporg-plugins' ); ?>" />
+ </p>
</ins><span class="cx" style="display: block; padding: 0 10px"> </form>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> <p><?php _e( '... or paste your <code>readme.txt</code> here:', 'wporg-plugins' ); ?></p>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <form method="post" action="<?php echo esc_url( add_query_arg( array() ) ); ?>">
- <input type="hidden" name="text" value="1" />
- <textarea rows="20" cols="100" name="readme_contents"></textarea>
- <p><input type="submit" value="Validate!" /></p>
- <?php
- wp_nonce_field( 'validate-readme-text' );
- ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <form method="post" action="">
+ <textarea rows="20" cols="100" name="readme_contents" placeholder="=== Plugin Name ==="><?php
+ if ( isset( $_POST['readme_contents'] ) ) {
+ echo esc_textarea( wp_unslash( $_POST['readme_contents'] ) );
+ }
+ ?></textarea>
+ <p><input type="submit" value="<?php esc_attr_e( 'Validate!', 'wporg-plugins' ); ?>" /></p>
</ins><span class="cx" style="display: block; padding: 0 10px"> </form>
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -70,39 +41,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Validates readme.txt contents and adds feedback.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function validate() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function validate_readme() {
+ if ( !empty( $_POST['readme_url'] ) ) {
+ $errors = Validator::instance()->validate_url( wp_unslash( $_POST['readme_url'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $readme = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( !empty( $_POST['readme_contents'] ) ) {
+ $errors = Validator::instance()->validate_content( wp_unslash( $_REQUEST['readme_contents'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !empty( $_POST['url'] )
- && !empty( $_POST['readme_url'] )
- && !empty( $_POST['_wpnonce'] )
- && wp_verify_nonce( $_POST['_wpnonce'], 'validate-readme-url' ) ) {
- $url = esc_url_raw( $_POST['readme_url'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else {
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( strtolower( substr( $url, -10 ) ) != 'readme.txt' ) {
- /* Translators: File name; */
- self::instance()->errors[] = sprintf( __( 'URL must end in %s!', 'wporg-plugins' ), '<code>readme.txt</code>' );
- return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $error_types = array(
+ 'errors' => __( 'Fatal Errors:', 'wporg-plugins' ),
+ 'warnings' => __( 'Warnings:', 'wporg-plugins' ),
+ 'notes' => __( 'Notes:', 'wporg-plugins' )
+ );
+ foreach ( $error_types as $field => $warning_label ) {
+ if ( !empty( $errors[ $field ] ) ) {
+ echo "{$warning_label}\n<ul class='{$field} error'>\n";
+ foreach ( $errors[ $field ] as $notice ) {
+ echo "<li>{$notice}</li>\n";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- if ( ! $readme = @file_get_contents( $url ) ) {
- self::instance()->errors[] = __( 'Invalid readme.txt URL.', 'wporg-plugins' );
- return;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ echo "</ul>\n";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- elseif ( !empty( $_POST['text'] )
- && !empty( $_POST['readme_contents'] )
- && !empty( $_POST['_wpnonce'] )
- && wp_verify_nonce( $_POST['_wpnonce'], 'validate-readme-text' ) ) {
- $readme = wp_unslash( $_REQUEST['readme_contents'] );
- }
-
- if ( empty( $readme ) ) {
- return;
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- return Validator::instance()->validate_content( $readme );
-
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>