<!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>[9993] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin dir: new files for block validator tool.</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 { white-space: pre-line; 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/9993">9993</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/9993","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>tellyworth</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-07-02 07:12:48 +0000 (Thu, 02 Jul 2020)</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 dir: new files for block validator tool.
Still WIP.</pre>
<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryblockjsonblockjson">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/block.json</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryblockjsonclassparserphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-parser.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryblockjsonclassvalidatorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-validator.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassblockplugincheckerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryshortcodesclassblockvalidatorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryblockjsonblockjson"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/block.json</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/block-json/block.json (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/block.json 2020-07-02 07:12:48 UTC (rev 9993)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,34 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+{
+ "name": "my-plugin/notice",
+ "title": "Notice",
+ "category": "text",
+ "parent": [ "core/group" ],
+ "icon": "star",
+ "description": "Shows warning, error or success notices ...",
+ "keywords": [ "alert", "message" ],
+ "textdomain": "my-plugin",
+ "attributes": {
+ "message": {
+ "type": "string",
+ "source": "html",
+ "selector": ".message"
+ }
+ },
+ "supports": {
+ "align": true,
+ "lightBlockWrapper": true
+ },
+ "styles": [
+ { "name": "default", "label": "Default", "isDefault": true },
+ { "name": "other", "label": "Other" }
+ ],
+ "example": {
+ "attributes": {
+ "message": "This is a notice!"
+ }
+ },
+ "editorScript": "build/editor.js",
+ "script": "build/main.js",
+ "editorStyle": "build/editor.css",
+ "style": "build/style.css"
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryblockjsonclassparserphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-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/block-json/class-parser.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-parser.php 2020-07-02 07:12:48 UTC (rev 9993)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,174 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Plugin_Directory\Block_JSON;
+
+use WP_Error;
+
+defined( 'WPINC' ) || die();
+
+/**
+ * Class Parser
+ *
+ * @package WordPressdotorg\Plugin_Directory\Block_JSON
+ */
+class Parser {
+ /**
+ * A location resource must be pointing to a file named this.
+ *
+ * @const string
+ */
+ const REQUIRED_FILENAME = 'block.json';
+
+ /**
+ * Parse the JSON content of a given resource into a PHP object.
+ *
+ * @param array $resource An associative array with one item where the key specifies the type of resource and the
+ * value represents the resource as a string. Valid types are `url`, `file`, and `content`.
+ * In this case, the value of `content` is expected to be a raw string of JSON, while the
+ * other two are expected to be the location of a file containing the JSON.
+ *
+ * @return object|WP_Error An object if the parse was successful, otherwise a WP_Error.
+ */
+ public static function parse( array $resource ) {
+ reset( $resource );
+ $type = key( $resource );
+ $handle = current( $resource );
+
+ switch ( $type ) {
+ case 'url':
+ $content = self::extract_content_from_url( $handle );
+ break;
+ case 'file':
+ $content = self::extract_content_from_file( $handle );
+ break;
+ case 'content':
+ $content = $handle;
+ break;
+ default:
+ $content = new WP_Error(
+ 'no_valid_resource',
+ __( 'No valid resource type was given.', 'wporg-plugins' )
+ );
+ break;
+ }
+
+ if ( is_wp_error( $content ) ) {
+ return $content;
+ }
+
+ return self::parse_content( $content );
+ }
+
+ /**
+ * Get the contents of a block.json file via an HTTP request to a URL.
+ *
+ * @param string $url
+ *
+ * @return string|WP_Error
+ */
+ protected static function extract_content_from_url( $url ) {
+ $url = esc_url_raw( $url );
+
+ $filename_length = strlen( self::REQUIRED_FILENAME );
+ if ( strtolower( substr( $url, - $filename_length ) ) !== self::REQUIRED_FILENAME ) {
+ return new WP_Error(
+ 'resource_url_invalid',
+ sprintf(
+ /* translators: %s: file name */
+ __( 'URL must end in %s!', 'wporg-plugins' ),
+ '<code>' . self::REQUIRED_FILENAME . '</code>'
+ )
+ );
+ }
+
+ $response = wp_safe_remote_get( $url );
+ $response_code = wp_remote_retrieve_response_code( $response );
+
+ if ( is_wp_error( $response ) ) {
+ return $response;
+ } elseif ( 200 !== $response_code ) {
+ return new WP_Error(
+ 'resource_url_unexpected_response',
+ __( 'URL returned an unexpected status code.', 'wporg-plugins' ),
+ array(
+ 'status' => $response_code,
+ )
+ );
+ }
+
+ return wp_remote_retrieve_body( $response );
+ }
+
+ /**
+ * Get the contents of a block.json file via a path in the filesystem.
+ *
+ * @param string $file
+ *
+ * @return string|WP_Error
+ */
+ protected static function extract_content_from_file( $file ) {
+ $filename_length = strlen( self::REQUIRED_FILENAME );
+ if ( strtolower( substr( $file, - $filename_length ) ) !== self::REQUIRED_FILENAME ) {
+ return new WP_Error(
+ 'resource_file_invalid',
+ sprintf(
+ /* translators: %s: file name */
+ __( 'File must be named %s!', 'wporg-plugins' ),
+ '<code>' . self::REQUIRED_FILENAME . '</code>'
+ )
+ );
+ }
+
+ if ( ! is_readable( $file ) ) {
+ return new WP_Error(
+ 'resource_file_unreadable',
+ __( 'The file could not be read.', 'wporg-plugins' ),
+ array(
+ 'file' => $file,
+ )
+ );
+ }
+
+ $content = file_get_contents( $file );
+
+ if ( false === $content ) {
+ return new WP_Error(
+ 'resource_file_failed_retrieval',
+ __( 'Could not get the contents of the file.', 'wporg-plugins' ),
+ array(
+ 'file' => $file,
+ )
+ );
+ }
+
+ return $content;
+ }
+
+ /**
+ * Parse a JSON string into an object, and handle parsing errors.
+ *
+ * @param string $content
+ *
+ * @return object|WP_Error
+ */
+ protected static function parse_content( $content ) {
+ $parsed = json_decode( $content );
+ $error = json_last_error_msg();
+
+ // TODO Once we are on PHP 7.3 we can use the JSON_THROW_ON_ERROR option and catch an exception here.
+ if ( 'No error' !== $error ) {
+ return new WP_Error(
+ 'json_parse_error',
+ sprintf(
+ __( 'JSON Parser: %s', 'wporg-plugins' ),
+ esc_html( $error )
+ ),
+ array(
+ 'error_code' => json_last_error(),
+ )
+ );
+ }
+
+ return $parsed;
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-parser.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryblockjsonclassvalidatorphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/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/block-json/class-validator.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-validator.php 2020-07-02 07:12:48 UTC (rev 9993)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,554 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Plugin_Directory\Block_JSON;
+
+use WP_Error;
+
+defined( 'WPINC' ) || die();
+
+/**
+ * Class Validator
+ *
+ * @package WordPressdotorg\Plugin_Directory\Block_JSON
+ */
+class Validator {
+ /**
+ * @var WP_Error
+ */
+ protected $messages;
+
+ /**
+ * Validator constructor.
+ */
+ public function __construct() {
+ $this->messages = new WP_Error();
+ }
+
+ /**
+ * The schema for the block.json file.
+ *
+ * This attempts to follow the schema for the schema.
+ * See https://json-schema.org/understanding-json-schema/reference/index.html
+ *
+ * @return array
+ */
+ public static function schema() {
+ return array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'attributes' => array(
+ 'type' => 'object',
+ 'additionalProperties' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'attribute' => array(
+ 'type' => 'string',
+ ),
+ 'meta' => array(
+ 'type' => 'string',
+ ),
+ 'multiline' => array(
+ 'type' => 'string',
+ ),
+ 'query' => array(
+ 'type' => 'object',
+ ),
+ 'selector' => array(
+ 'type' => 'string',
+ ),
+ 'source' => array(
+ 'type' => 'string',
+ 'enum' => array( 'attribute', 'text', 'html', 'query' ),
+ ),
+ 'type' => array(
+ 'type' => 'string',
+ 'enum' => array( 'null', 'boolean', 'object', 'array', 'number', 'string', 'integer' ),
+ ),
+ ),
+ 'required' => array( 'type' ),
+ ),
+ ),
+ 'category' => array(
+ 'type' => 'string',
+ ),
+ 'comment' => array(
+ 'type' => 'string',
+ ),
+ 'description' => array(
+ 'type' => 'string',
+ ),
+ 'editorScript' => array(
+ 'type' => 'string',
+ 'pattern' => '\.js$',
+ ),
+ 'editorStyle' => array(
+ 'type' => 'string',
+ 'pattern' => '\.css$',
+ ),
+ 'example' => array(
+ 'type' => 'object',
+ 'additionalProperties' => array(
+ 'type' => 'object',
+ ),
+ ),
+ 'icon' => array(
+ 'type' => 'string',
+ ),
+ 'keywords' => array(
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'string',
+ ),
+ ),
+ 'name' => array(
+ 'type' => 'string',
+ ),
+ 'parent' => array(
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'string',
+ ),
+ ),
+ 'script' => array(
+ 'type' => 'string',
+ 'pattern' => '\.js$',
+ ),
+ 'style' => array(
+ 'type' => 'string',
+ 'pattern' => '\.css$',
+ ),
+ 'styles' => array(
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'isDefault' => array(
+ 'type' => 'boolean',
+ ),
+ 'label' => array(
+ 'type' => 'string',
+ ),
+ 'name' => array(
+ 'type' => 'string',
+ ),
+ ),
+ ),
+ ),
+ 'supports' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'align' => array(
+ 'type' => array( 'boolean', 'array' ),
+ 'items' => array(
+ 'type' => 'string',
+ 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
+ ),
+ ),
+ 'alignWide' => array(
+ 'type' => 'boolean',
+ ),
+ 'anchor' => array(
+ 'type' => 'boolean',
+ ),
+ 'className' => array(
+ 'type' => 'boolean',
+ ),
+ 'customClassName' => array(
+ 'type' => 'boolean',
+ ),
+ 'html' => array(
+ 'type' => 'boolean',
+ ),
+ 'inserter' => array(
+ 'type' => 'boolean',
+ ),
+ 'multiple' => array(
+ 'type' => 'boolean',
+ ),
+ 'reusable' => array(
+ 'type' => 'boolean',
+ ),
+ ),
+ ),
+ 'textdomain' => array(
+ 'type' => 'string',
+ ),
+ 'title' => array(
+ 'type' => 'string',
+ ),
+ ),
+ 'required' => array( 'name', 'title' ),
+ 'additionalProperties' => false,
+ );
+ }
+
+ /**
+ * Validate a PHP object representation of a block.json file.
+ *
+ * @param object|WP_Error $block_json
+ *
+ * @return bool|WP_Error
+ */
+ public function validate( $block_json ) {
+ // A WP_Error instance is technically an object, but shouldn't be validated.
+ if ( is_wp_error( $block_json ) ) {
+ return $block_json;
+ }
+
+ $schema = self::schema();
+
+ $this->validate_object( $block_json, 'block.json', $schema );
+ $this->check_conditional_properties( $block_json );
+
+ if ( $this->messages->has_errors() ) {
+ return $this->messages;
+ }
+
+ return true;
+ }
+
+ /**
+ * Check for properties that are conditionally required.
+ *
+ * @param object $block_json
+ *
+ * @return void
+ */
+ protected function check_conditional_properties( $block_json ) {
+ if ( ! is_object( $block_json ) ) {
+ return;
+ }
+
+ if ( ! isset( $block_json->script ) && ! isset( $block_json->editorScript ) ) {
+ $this->messages->add(
+ 'error',
+ sprintf(
+ __( 'At least one of the following properties must be present: %s', 'wporg-plugins' ),
+ // translators: used between list items, there is a space after the comma.
+ '<code>script</code>' . __( ', ', 'wporg-plugins' ) . '<code>editorScript</code>'
+ )
+ );
+ $this->append_error_data( 'block.json:script', 'error' );
+ $this->append_error_data( 'block.json:editorScript', 'error' );
+ }
+
+ if ( ! isset( $block_json->style ) && ! isset( $block_json->editorStyle ) ) {
+ $this->messages->add(
+ 'error',
+ sprintf(
+ __( 'At least one of the following properties must be present: %s', 'wporg-plugins' ),
+ // translators: used between list items, there is a space after the comma.
+ '<code>style</code>' . __( ', ', 'wporg-plugins' ) . '<code>editorStyle</code>'
+ )
+ );
+ $this->append_error_data( 'block.json:style', 'error' );
+ $this->append_error_data( 'block.json:editorStyle', 'error' );
+ }
+ }
+
+ /**
+ * Validate an object and its properties.
+ *
+ * @param object $object The value to validate as an object.
+ * @param string $prop The name of the property, used in error reporting.
+ * @param array $schema The schema for the property, used for validation.
+ *
+ * @return bool
+ */
+ protected function validate_object( $object, $prop, $schema ) {
+ if ( ! is_object( $object ) ) {
+ $this->messages->add(
+ 'error',
+ sprintf(
+ __( 'The %s property must contain an object value.', 'wporg-plugins' ),
+ '<code>' . $prop . '</code>'
+ )
+ );
+ $this->append_error_data( $prop, 'error' );
+
+ return false;
+ }
+
+ $results = array();
+
+ if ( isset( $schema['required'] ) ) {
+ foreach ( $schema['required'] as $required_prop ) {
+ if ( ! property_exists( $object, $required_prop ) ) {
+ $this->messages->add(
+ 'error',
+ sprintf(
+ __( 'The %1$s property is required in the %2$s object.', 'wporg-plugins' ),
+ '<code>' . $required_prop . '</code>',
+ '<code>' . $prop . '</code>'
+ )
+ );
+ $this->append_error_data( "$prop:$required_prop", 'error' );
+ $results[] = false;
+ }
+ }
+ }
+
+ if ( isset( $schema['properties'] ) ) {
+ foreach ( $schema['properties'] as $subprop => $subschema ) {
+ if ( ! isset( $object->$subprop ) ) {
+ continue;
+ }
+
+ if ( isset( $subschema['type'] ) ) {
+ $results[] = $this->route_validation_for_type(
+ $subschema['type'],
+ $object->$subprop,
+ "$prop:$subprop",
+ $subschema
+ );
+ }
+ }
+ }
+
+ if ( isset( $schema['additionalProperties'] ) ) {
+ if ( false === $schema['additionalProperties'] ) {
+ foreach ( array_keys( get_object_vars( $object ) ) as $key ) {
+ if ( ! isset( $schema['properties'][ $key ] ) ) {
+ $this->messages->add(
+ 'warning',
+ sprintf(
+ __( '%1$s is not a valid property in the %2$s object.', 'wporg-plugins' ),
+ '<code>' . $key . '</code>',
+ '<code>' . $prop . '</code>'
+ )
+ );
+ $this->append_error_data( "$prop:$key", 'warning' );
+ $results[] = false;
+ continue;
+ }
+ }
+ } elseif ( isset( $schema['additionalProperties']['type'] ) ) {
+ foreach ( $object as $subprop => $subvalue ) {
+ $results[] = $this->route_validation_for_type(
+ $schema['additionalProperties']['type'],
+ $subvalue,
+ "$prop:$subprop",
+ $schema['additionalProperties']
+ );
+ }
+ }
+ }
+
+ return ! in_array( false, $results, true );
+ }
+
+ /**
+ * Validate an array and its items.
+ *
+ * @param array $array The value to validate as an array.
+ * @param string $prop The name of the property, used in error reporting.
+ * @param array $schema The schema for the property, used for validation.
+ *
+ * @return bool
+ */
+ protected function validate_array( $array, $prop, $schema ) {
+ if ( ! is_array( $array ) ) {
+ $this->messages->add(
+ 'error',
+ sprintf(
+ __( 'The %s property must contain an array value.', 'wporg-plugins' ),
+ '<code>' . $prop . '</code>'
+ )
+ );
+ $this->append_error_data( $prop, 'error' );
+
+ return false;
+ }
+
+ if ( isset( $schema['items']['type'] ) ) {
+ $results = array();
+ $index = 0;
+
+ foreach ( $array as $item ) {
+ $results[] = $this->route_validation_for_type(
+ $schema['items']['type'],
+ $item,
+ $prop . "[$index]",
+ $schema['items']
+ );
+ $index ++;
+ }
+
+ return ! in_array( false, $results, true );
+ }
+
+ return true;
+ }
+
+ /**
+ * Validate a string.
+ *
+ * @param string $string The value to validate as a string.
+ * @param string $prop The name of the property, used in error reporting.
+ * @param array $schema The schema for the property, used for validation.
+ *
+ * @return bool
+ */
+ protected function validate_string( $string, $prop, $schema ) {
+ if ( ! is_string( $string ) ) {
+ $this->messages->add(
+ 'error',
+ sprintf(
+ __( 'The %s property must contain a string value.', 'wporg-plugins' ),
+ '<code>' . $prop . '</code>'
+ )
+ );
+ $this->append_error_data( $prop, 'error' );
+
+ return false;
+ }
+
+ if ( isset( $schema['enum'] ) ) {
+ if ( ! in_array( $string, $schema['enum'], true ) ) {
+ $this->messages->add(
+ 'warning',
+ sprintf(
+ __( '"%1$s" is not a valid value for the %2$s property.', 'wporg-plugins' ),
+ esc_html( $string ),
+ '<code>' . $prop . '</code>'
+ )
+ );
+ $this->append_error_data( $prop, 'warning' );
+ }
+ }
+
+ if ( isset( $schema['pattern'] ) ) {
+ if ( ! preg_match( '#' . $schema['pattern'] . '#', $string ) ) {
+ $pattern_description = $this->get_human_readable_pattern_description( $schema['pattern'] );
+ if ( $pattern_description ) {
+ $message = sprintf(
+ $pattern_description,
+ '<code>' . $prop . '</code>'
+ );
+ } else {
+ $message = sprintf(
+ __( 'The value of %s does not match the required pattern.', 'wporg-plugins' ),
+ '<code>' . $prop . '</code>'
+ );
+ }
+
+ $this->messages->add( 'warning', $message );
+ $this->append_error_data( $prop, 'warning' );
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Validate a boolean.
+ *
+ * @param bool $boolean The value to validate as a boolean.
+ * @param string $prop The name of the property, used in error reporting.
+ *
+ * @return bool
+ */
+ protected function validate_boolean( $boolean, $prop ) {
+ if ( ! is_bool( $boolean ) ) {
+ $this->messages->add(
+ 'error',
+ sprintf(
+ __( 'The %s property must contain a boolean value.', 'wporg-plugins' ),
+ '<code>' . $prop . '</code>'
+ )
+ );
+ $this->append_error_data( $prop, 'error' );
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Send a property value to the correct validator depending on which type(s) it can be.
+ *
+ * @param string|array $valid_types
+ * @param mixed $value
+ * @param string $prop
+ * @param array $schema
+ *
+ * @return bool
+ */
+ protected function route_validation_for_type( $valid_types, $value, $prop, $schema ) {
+ // There is a single valid type.
+ if ( is_string( $valid_types ) ) {
+ $method = "validate_$valid_types";
+ return $this->$method( $value, $prop, $schema );
+ }
+
+ // There are multiple valid types in an array.
+ foreach ( $valid_types as $type ) {
+ switch ( $type ) {
+ case 'boolean':
+ $check = 'is_bool';
+ break;
+ default:
+ $check = "is_$type";
+ break;
+ }
+
+ if ( $check( $value ) ) {
+ $method = "validate_$type";
+ return $this->$method( $value, $prop, $schema );
+ }
+ }
+
+ // Made it this far, it's none of the valid types.
+ $this->messages->add(
+ 'error',
+ sprintf(
+ __( 'The %1$s property must contain a value that is one of these types: %2$s', 'wporg-plugins' ),
+ '<code>' . $prop . '</code>',
+ // translators: used between list items, there is a space after the comma.
+ '<code>' . implode( '</code>' . __( ', ', 'wporg-plugins' ) . '<code>', $valid_types ) . '</code>'
+ )
+ );
+ $this->append_error_data( $prop, 'error' );
+
+ return false;
+ }
+
+ /**
+ * Add more data to an error code.
+ *
+ * The `add_data` method in WP_Error replaces data with each subsequent call with the same error code.
+ *
+ * @param mixed $new_data The data to append.
+ * @param string $error_code The error code to assign the data to.
+ *
+ * @return void
+ */
+ protected function append_error_data( $new_data, $error_code ) {
+ $data = $this->messages->get_error_data( $error_code ) ?: array();
+ $data[] = $new_data;
+ $this->messages->add_data( $data, $error_code );
+ }
+
+ /**
+ * Get a description of a regex pattern that can be understood by humans.
+ *
+ * @param string $pattern A regex pattern.
+ *
+ * @return string
+ */
+ protected function get_human_readable_pattern_description( $pattern ) {
+ $description = '';
+
+ switch ( $pattern ) {
+ case '\.css$':
+ $description = __( 'The value of %s must end in ".css".', 'wporg-plugins' );
+ break;
+ case '\.js$':
+ $description = __( 'The value of %s must end in ".js".', 'wporg-plugins' );
+ break;
+ }
+
+ return $description;
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-validator.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassblockplugincheckerphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.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-block-plugin-checker.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php 2020-07-02 07:12:48 UTC (rev 9993)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,493 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\CLI;
+
+use WordPressdotorg\Plugin_Directory\Readme\Parser as Readme_Parser;
+use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
+use WordPressdotorg\Plugin_Directory\Tools\SVN;
+use WordPressdotorg\Plugin_Directory\Block_JSON\Parser as Block_JSON_Parser;
+use WordPressdotorg\Plugin_Directory\Block_JSON\Validator as Block_JSON_Validator;
+
+/**
+ * A class that can examine a plugin, and evaluate and return status info that would be useful for a validator or similar tool.
+ *
+ * Note: I've written this as one class for convenience, but as it's evolved I think it would make sense to split it in two: one for collecting data
+ * (particularly the prepare*() and find*() functions), and a separate class for the checks.
+ *
+ * @package WordPressdotorg\Plugin_Directory\CLI
+ */
+class Block_Plugin_Checker {
+
+ protected $allowed_hosts = array(
+ 'github.com',
+ 'plugins.svn.wordpress.org',
+ );
+
+ protected $path_to_plugin = null;
+ protected $check_methods = array();
+ protected $results = array();
+
+ public $slug = null;
+ public $repo_url = null;
+ public $repo_revision = null;
+ protected $readme_path = null;
+ protected $readme = null;
+ protected $headers = null;
+ protected $blocks = null;
+ protected $block_json_files = null;
+ protected $block_json_validation = array();
+
+ /**
+ * Constructor.
+ *
+ * @param string $slug The plugin slug, if known. Optional.
+ */
+ public function __construct( $slug = null ) {
+ $this->slug = $slug;
+ }
+
+ /**
+ * Check a plugin given the URL of a Subversion or GitHub repo.
+ * Note that only hosts listed in $allowed_hosts are permitted.
+ *
+ * @param string $url The URL of a Subversion or GitHub repository.
+ * @return array A list of status items.
+ */
+ public function run_check_plugin_repo( $url ) {
+
+ // git@github.com:sortabrilliant/jumbotron.git
+
+ if ( preg_match( '#^\w+@github[.]com:(\w+/[^.]+)(?:\.git)?$#', $url, $matches ) ) {
+ $url = 'https://github.com/' . $matches[1];
+ }
+
+ // Parse the URL with whitespace and trailing / trimmed
+ $url_parts = wp_parse_url( rtrim( trim( $url ), '/' ) );
+
+ if ( empty( $url_parts ) ) {
+ $this->record_result(
+ __FUNCTION__,
+ 'error',
+ sprintf( __( 'Invalid url %s', 'wporg-plugins' ), $url ),
+ $url
+ );
+ return $this->results;
+ }
+
+ if ( empty( $url_parts['host'] ) || !in_array( $url_parts['host'], $this->allowed_hosts ) ) {
+ $this->record_result(
+ __FUNCTION__,
+ 'error',
+ sprintf( __( 'URL must be GitHub or plugins.svn.wordpress.org %s', 'wporg-plugins' ), $url ),
+ $url
+ );
+ return $this->results;
+ }
+
+ if ( 'plugins.svn.wordpress.org' === $url_parts['host'] ) {
+ $path_parts = explode( '/', $url_parts[ 'path' ], 3 );
+ if ( empty( $path_parts[1] ) ) {
+ $this->record_result(
+ __FUNCTION__,
+ 'error',
+ sprintf( __( 'URL must be a plugin repository %s', 'wporg-plugins' ), $url ),
+ $url
+ );
+ return $this->results;
+ }
+
+ $this->slug = $path_parts[1];
+ $url = 'https://plugins.svn.wordpress.org/' . $path_parts[1];
+ if ( 4 === count( $path_parts )
+ && ( 'tags' === $path_parts[2] || 'branches' === $path_parts[2] )
+ && ( !empty( $path_parts[3] ) ) ) {
+ $url .= $path_parts[2] . '/' . $path_parts[3];
+ } else {
+ $url .= '/trunk';
+ }
+ } elseif ( 'github.com' === $url_parts['host'] ) {
+ // https://github.com/sortabrilliant/jumbotron
+ // git@github.com:sortabrilliant/jumbotron.git
+ // https://github.com/sortabrilliant/jumbotron.git
+ //
+ if ( preg_match( '#^/(\w+/[^.]+)(?:\.git)?$#', $url_parts[ 'path' ], $matches ) ) {
+ $url = 'https://github.com/' . $matches[1] . '.git/trunk';
+ } else {
+ $this->record_result(
+ __FUNCTION__,
+ 'error',
+ sprintf( __( 'URL must be a plugin repository %s', 'wporg-plugins' ), $url ),
+ $url
+ );
+ return $this->results;
+ }
+ }
+
+ $url = esc_url_raw( $url );
+
+ $path = $this->export_plugin( $url );
+
+ if ( $path ) {
+ $result = $this->run_check_plugin_files( $path );
+
+ return $result;
+ } else {
+ return $this->results;
+ }
+
+ }
+
+ function export_plugin( $svn_url ) {
+
+
+ // Generate a unique tmp file directory name, but don't create it.
+ $path = Filesystem::temp_directory( '/tmp/blockplugin' );
+
+ $export = SVN::export( $svn_url, $path, array( 'ignore-externals', 'force' ) );
+ if ( $export['result'] ) {
+ $this->repo_revision = $export['revision'];
+ $this->repo_url = $svn_url;
+ return $path;
+ } else {
+ $this->record_result(
+ __FUNCTION__,
+ 'error',
+ sprintf( __( 'Error fetching repository %s: %s', 'wporg-plugins' ), $svn_url, $export['errors'][0]['error_code'] ),
+ $export['errors']
+ );
+ return false;
+ }
+
+ }
+
+ /**
+ * Check a plugin that has been unzipped or exported to a local filesystem.
+ *
+ * @param string $path_to_plugin Location where the plugin has been stored.
+ * @return array A list of status items.
+ */
+ public function run_check_plugin_files( $path_to_plugin ) {
+ $this->path_to_plugin = $path_to_plugin;
+ $this->init();
+ $this->prepare_data();
+ $this->run_all_checks();
+ return $this->results;
+ }
+
+ protected function init() {
+
+ // Find all the methods on this class starting with `check_`
+ $methods = get_class_methods( $this );
+ foreach ( $methods as $method ) {
+ if ( 0 === strpos( $method, 'check_' ) )
+ $this->check_methods[] = $method;
+ }
+ }
+
+ protected function prepare_data() {
+ // Parse and stash the readme data
+ $this->readme_path = Import::find_readme_file( $this->path_to_plugin );
+ $this->readme = new Readme_Parser( $this->readme_path );
+
+ // Parse and stash plugin headers
+ $this->headers = Import::find_plugin_headers( $this->path_to_plugin );
+
+ // Parse and stash block info
+ $this->blocks = $this->find_blocks( $this->path_to_plugin );
+
+ foreach ( $this->block_json_files as $block_json_file ) {
+ $validator = new Block_JSON_Validator();
+ $block_json = Block_JSON_Parser::parse( array( 'file' => $block_json_file ) );
+ $this->block_json_validation[ $block_json_file ] = $validator->validate( $block_json );
+ }
+ }
+
+ public function relative_filename( $filename ) {
+ return str_replace( "{$this->path_to_plugin}/", '', $filename );
+ }
+
+ public function run_all_checks() {
+ foreach ( array_unique( $this->check_methods ) as $method ) {
+ call_user_func( array( $this, $method ) );
+ }
+ }
+
+ public function find_blocks( $base_dir ) {
+ $this->block_json_files = Filesystem::list_files( $base_dir, true, '!(?:^|/)block\.json$!i' );
+ if ( false && ! empty( $this->block_json_files ) ) {
+ foreach ( $block_json_files as $filename ) {
+ $blocks_in_file = Import::find_blocks_in_file( $filename );
+ $relative_filename = $this->relative_filename( $filename );
+ $potential_block_directories[] = dirname( $relative_filename );
+ foreach ( $blocks_in_file as $block ) {
+ $blocks[ $block->name ] = $block;
+ }
+ }
+ } else {
+ foreach ( Filesystem::list_files( $base_dir, true, '!\.(?:php|js|jsx)$!i' ) as $filename ) {
+ $blocks_in_file = Import::find_blocks_in_file( $filename );
+ if ( ! empty( $blocks_in_file ) ) {
+ $relative_filename = $this->relative_filename( $filename );
+ $potential_block_directories[] = dirname( $relative_filename );
+ foreach ( $blocks_in_file as $block ) {
+ if ( preg_match( '!\.(?:js|jsx)$!i', $relative_filename ) && empty( $block->script ) )
+ $block->script = $relative_filename;
+ $blocks[ $block->name ] = $block;
+ }
+ }
+ }
+ }
+
+ return $blocks;
+ }
+
+ public function find_block_scripts() {
+ $block_scripts = array();
+ foreach ( $this->blocks as $block ) {
+ $scripts = Import::extract_file_paths_from_block_json( $block );
+ if ( isset( $block_scripts[ $block->name ] ) ) {
+ $block_scripts[ $block->name ] = array_merge( $block_scripts[ $block->name ], $scripts );
+ } else {
+ $block_scripts[ $block->name ] = $scripts;
+ }
+ }
+
+ return $block_scripts;
+ }
+
+ /**
+ * Used by check_*() functions to record info.
+ *
+ * @param string $check_name An unambiguous name of the check. Should normally be the calling __FUNCTION__.
+ * @param string $type The type of info being recorded: 'error', 'problem', 'info', etc.
+ * @param string $message A human-readable message explaining the info.
+ * @param mixed $data Additional data related to the info, optional. Typically a string or array.
+ */
+ protected function record_result( $check_name, $type, $message, $data = null ) {
+ $this->results[] = (object) array(
+ 'check_name' => $check_name,
+ 'type' => $type,
+ 'message' => $message,
+ 'data' => $data );
+ }
+
+ /**
+ * Check functions below here. Must be named `check_*()`.
+ */
+
+ /**
+ * Readme.txt file must be present.
+ */
+ function check_readme_exists() {
+ if ( empty( $this->readme_path ) || !file_exists( $this->readme_path ) ) {
+ $this->record_result( __FUNCTION__,
+ 'error',
+ __( 'Missing readme.txt file', 'wporg-plugins' ),
+ $this->relative_filename( $this->readme_path )
+ );
+ }
+ }
+
+ /**
+ * Readme should have a license.
+ */
+ function check_license() {
+ if ( empty( $this->readme->license ) ) {
+ $this->record_result( __FUNCTION__,
+ 'warning',
+ __( 'Missing license in readme.txt.', 'wporg-plugins' )
+ );
+ } else {
+ $this->record_result( __FUNCTION__,
+ 'info',
+ __( 'Found a license in readme.txt.', 'wporg-plugins' ),
+ $this->readme->license
+ );
+ }
+ }
+
+ /**
+ * Does the plugin have a block name that already exists in the DB?
+ * Note that this isn't a blocker if we're re-running checks on a plugin that has already been uploaded, since it will match with itself.
+ */
+ function check_for_duplicate_block_name() {
+ foreach ( $this->blocks as $block ) {
+ if ( !trim( strval( $block->name ) ) )
+ continue;
+
+ $query_args = array(
+ 'post_type' => 'plugin',
+ 'meta_query' => array(
+ array(
+ 'key' => 'block_name',
+ 'value' => $block->name,
+ )
+ )
+ );
+
+ $query = new \WP_Query( $query_args );
+ if ( $query->found_posts > 0 ) {
+ foreach ( $query->posts as $post ) {
+ if ( $this->slug && $this->slug === $post->post_name )
+ continue; // It's this very same plugin
+
+ $this->record_result( __FUNCTION__,
+ 'info',
+ sprintf( __( 'Block name already exists in plugin %s', 'wporg-plugins' ), $query->posts[0]->post_name ),
+ [ 'block_name' => $block->name, 'slug' => $post->post_name ]
+ );
+ }
+ }
+ }
+
+ }
+
+ /**
+ * There should be at least one block.
+ */
+ function check_for_blocks() {
+ if ( 0 === count( $this->blocks ) ) {
+ $this->record_result( __FUNCTION__,
+ 'error',
+ __( 'No blocks found in plugin.', 'wporg-plugins' )
+ );
+ } else {
+ $this->record_result( __FUNCTION__,
+ 'info',
+ sprintf( _n( 'Found %d block', 'Found %d blocks', count( $this->blocks ), 'wporg-plugins' ), count( $this->blocks ) ),
+ array_keys( $this->blocks )
+ );
+ }
+ }
+
+ /**
+ * Every block should have a block.json file, ideally.
+ */
+ function check_for_block_json() {
+ foreach ( $this->blocks as $block_name => $block_info ) {
+ if ( !empty( $this->block_json_files[ $block_name ] ) ) {
+ $this->record_result( __FUNCTION__,
+ 'info',
+ sprintf( __( 'block.json file exists for block %s', 'wporg-plugins' ), $block_name ),
+ $this->block_json_files[ $block_name ]
+ );
+ }
+ }
+
+ if ( empty( $this->block_json_files ) ) {
+ $this->record_result( __FUNCTION__,
+ 'warning',
+ __( 'No block.json files were found', 'wporg-plugins' )
+ );
+ }
+ }
+
+ /**
+ * Do the blocks all have available script assets, either discoverable or in the block.json file?
+ */
+ function check_for_block_scripts() {
+ $block_scripts = $this->find_block_scripts();
+
+ foreach ( $this->blocks as $block_name => $block_info ) {
+ if ( !empty( $block_scripts[ $block_name ] ) ) {
+ $this->record_result( __FUNCTION__,
+ 'info',
+ sprintf( __( 'Scripts found for block %s', 'wporg-plugins' ), $block_name ),
+ $block_scripts[ $block_name ]
+ );
+ } else {
+ $this->record_result( __FUNCTION__,
+ 'warning',
+ sprintf( __( 'No scripts found for block %s', 'wporg-plugins' ), $block_name ),
+ $block_name
+ );
+ }
+ }
+ }
+
+ /**
+ * Do the script files all exist?
+ */
+ function check_for_block_script_files() {
+ foreach ( $this->find_block_scripts() as $block_name => $scripts ) {
+ foreach ( $scripts as $script ) {
+ if ( file_exists( $this->path_to_plugin . $script ) ) {
+ $this->record_result( __FUNCTION__,
+ 'info',
+ sprintf( __( 'Script file exists for block %s', 'wporg-plugins' ), $block_name ),
+ $script
+ );
+ } else {
+ $this->record_result( __FUNCTION__,
+ 'warning',
+ sprintf( __( 'Missing script file for block %s', 'wporg-plugins' ), $block_name ),
+ $script
+ );
+ }
+ }
+ }
+ }
+
+ /**
+ * Does the JS call registerBlockType?
+ */
+ function check_for_register_block_type() {
+ $block_files = array();
+ foreach ( Filesystem::list_files( $this->path_to_plugin, true, '!\.(?:js|jsx)$!i' ) as $filename ) {
+ $js = file_get_contents( $filename );
+ // TODO: need something better than this. find_blocks_in_file() misses quite a few unfortunately.
+ if ( false !== strpos( $js, 'registerBlockType' ) ) {
+ $block_files[] = $filename;
+ }
+ unset( $js );
+ }
+
+ if ( empty( $block_files ) ) {
+ $this->record_result( __FUNCTION__,
+ 'error',
+ sprintf( __( 'registerBlockType() must be called in a JavaScript file', 'wporg-plugins' ) )
+ );
+ }
+ }
+
+ /**
+ * Are the block.json files parseable?
+ */
+ function check_block_json_is_valid_json() {
+ foreach ( $this->block_json_validation as $block_json_file => $result ) {
+ if ( is_wp_error( $result ) ) {
+ if ( $message = $result->get_error_message( 'json_parse_error' ) ) {
+ $this->record_result( __FUNCTION__,
+ 'error',
+ sprintf( __( 'Error attempting to parse json in %s: %s', 'wporg-plugins' ), $this->relative_filename( $block_json_file ), $message ),
+ $this->relative_filename( $block_json_file )
+ );
+ }
+ }
+ }
+ }
+
+ /**
+ * Are the block.json files valid?
+ */
+ function check_block_json_is_valid() {
+ foreach ( $this->block_json_validation as $block_json_file => $result ) {
+ foreach ( $result->get_error_codes() as $code ) {
+ $messages = $result->get_error_messages( $code );
+ foreach ( $messages as $i => $message ) {
+ if ( 'json_parse_error' === $code ) {
+ continue; // Already handled in check_block_json_is_valid_json
+ } else {
+ $this->record_result( __FUNCTION__,
+ ( 'error' === $code ? 'warning' : $code ), // TODO: be smarter about mapping these
+ $message,
+ array(
+ $this->relative_filename( $block_json_file ),
+ $result->get_error_data( $code )
+ )
+ );
+ }
+ }
+ }
+ }
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryshortcodesclassblockvalidatorphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-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-block-validator.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php 2020-07-02 07:12:48 UTC (rev 9993)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,84 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Shortcodes;
+
+use WordPressdotorg\Plugin_Directory\CLI\Block_Plugin_Checker;
+
+class Block_Validator {
+
+ /**
+ * Displays a form to validate block plugins.
+ */
+ public static function display() {
+ ?>
+ <div class="wrap">
+<?php
+ if ( $_POST && wp_verify_nonce( $_POST['block-nonce'], 'validate-block-plugin' ) ) {
+
+ self::validate_block( $_POST['plugin_url'] );
+ }
+
+ $plugin_url = $_REQUEST['plugin_url'] ?? '';
+ ?>
+
+ <form method="post" action="">
+ <p>
+ <input type="text" name="plugin_url" size="70" placeholder="https://plugins.svn.wordpress.org/" value="<?php echo esc_url( $plugin_url ); ?>" />
+ <input type="submit" class="button button-secondary" value="<?php esc_attr_e( 'Validate!', 'wporg-plugins' ); ?>" />
+ <?php wp_nonce_field( 'validate-block-plugin', 'block-nonce' ); ?>
+ </p>
+ </form>
+
+ </div>
+ <?php
+ }
+
+ /**
+ * Validates readme.txt contents and adds feedback.
+ */
+ protected static function validate_block( $plugin_url ) {
+
+ $checker = new Block_Plugin_Checker();
+ $results = $checker->run_check_plugin_repo( $plugin_url );
+
+ if ( $checker->repo_url && $checker->repo_revision ) {
+ echo '<h2>Validating..</h2>';
+ echo '<p>Results for ' . esc_url( $checker->repo_url ) . ' revision ' . esc_html( $checker->repo_revision ) . '</p>';
+ }
+
+ $results_by_type = array();
+ foreach ( $results as $item ) {
+ $results_by_type[ $item->type ][] = $item;
+ }
+
+
+ $output = '';
+
+ $error_types = array(
+ 'error' => __( 'Fatal Errors:', 'wporg-plugins' ),
+ 'warning' => __( 'Warnings:', 'wporg-plugins' ),
+ 'info' => __( 'Notes:', 'wporg-plugins' ),
+ );
+ foreach ( $error_types as $type => $warning_label ) {
+
+ if ( empty( $results_by_type[ $type ] ) )
+ continue;
+
+ $output .= "<h3>{$warning_label}</h3>\n";
+ $output .= "<div class='notice notice-{$type} notice-alt'>\n";
+ $output .= "<ul class='{$type}'>\n";
+ foreach ( $results_by_type[ $type ] as $item ) {
+ $output .= "<li title='{$item->check_name}'><a href='/hypothetical/doc/page#{$item->check_name}'><span class='dashicons dashicons-info'></span></a> {$item->message}</li>\n";
+ }
+ $output .= "</ul>\n";
+ $output .= "</div>\n";
+ }
+
+ if ( empty( $output ) ) {
+ $output .= '<div class="notice notice-success notice-alt">';
+ $output .= '<p>' . __( 'Congratulations! No errors found.', 'wporg-plugins' ) . '</p>';
+ $output .= '</div>';
+ }
+
+ echo $output;
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>