<!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>[2640] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Upload shortcode: Abstract out the filesystem handling and cleanup remaining themes-specific logic which don't apply to plugins.</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/2640">2640</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/2640","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-02-26 07:52:43 +0000 (Fri, 26 Feb 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: Upload shortcode: Abstract out the filesystem handling and cleanup remaining themes-specific logic which don't apply to plugins.
See <a href="http://meta.trac.wordpress.org/ticket/1569">#1569</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassplugindirectoryphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.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>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryshortcodesclassuploadphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorytoolsclassfilesystemphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-filesystem.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassplugindirectoryphp"></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/class-plugin-directory.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-plugin-directory.php      2016-02-26 07:49:53 UTC (rev 2639)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php        2016-02-26 07:52:43 UTC (rev 2640)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -327,7 +327,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @param $plugin_slug string|\WP_Post The slug of the plugin to retrieve.
</span><span class="cx" style="display: block; padding: 0 10px">         * @return \WP_Post|\WP_Error
</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 get_plugin_post( $plugin_slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static public function get_plugin_post( $plugin_slug ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( $plugin_slug instanceof \WP_Post ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return $plugin_slug;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -336,7 +336,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $posts = get_posts( array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_type'   => 'plugin',
</span><span class="cx" style="display: block; padding: 0 10px">                        'name'        => $plugin_slug,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'post_status' => 'any',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'post_status' => array( 'publish', 'pending', 'disabled', 'closed' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! $posts ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -359,7 +359,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * }
</span><span class="cx" style="display: block; padding: 0 10px">         * @return \WP_Post|\WP_Error
</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 create_plugin_post( array $plugin_info ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static public function create_plugin_post( array $plugin_info ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $title  = !empty( $plugin_info['title'] )       ? $plugin_info['title']       : '';
</span><span class="cx" style="display: block; padding: 0 10px">                $slug   = !empty( $plugin_info['slug'] )        ? $plugin_info['slug']        : sanitize_title( $title );
</span><span class="cx" style="display: block; padding: 0 10px">                $status = !empty( $plugin_info['status'] )      ? $plugin_info['status']      : 'pending';
</span></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-02-26 07:49:53 UTC (rev 2639)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php       2016-02-26 07:52:43 UTC (rev 2640)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,5 +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\Shortcodes;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Plugin_Directory\Plugin_Directory;
+use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
</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">  * The [wporg-plugin-upload] shortcode handler to display a plugin uploader.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,36 +11,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class Upload_Handler {
</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">-         * Path to `rm` script.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Path to temporary plugin folder.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @var string
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        const RM = '/bin/rm';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $plugin_dir;
</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">-         * Path to `unzip` script.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Path to the detected plugins files.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @var string
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        const UNZIP = '/usr/bin/unzip';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $plugin_root;
</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">-         * Path to temporary directory.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * The uploaded plugin headers.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @var string
-        */
-       protected $tmp_dir;
-
-       /**
-        * Path to temporary plugin folder.
-        *
-        * @var string
-        */
-       protected $plugin_dir;
-
-       /**
-        * The uploaded plugin.
-        *
</del><span class="cx" style="display: block; padding: 0 10px">          * @var array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        protected $plugin;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -51,20 +39,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">        protected $plugin_slug;
</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">-         * The plugin post if it already exists in the repository.
-        *
-        * @var \WP_Post
-        */
-       protected $plugin_post;
-
-       /**
-        * The plugin author (current user).
-        *
-        * @var \WP_User
-        */
-       protected $author;
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Get set up to run tests on the uploaded plugin.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function __construct() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -72,11 +46,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                require_once( ABSPATH . 'wp-admin/includes/image.php' );
</span><span class="cx" style="display: block; padding: 0 10px">                require_once( ABSPATH . 'wp-admin/includes/file.php' );
</span><span class="cx" style="display: block; padding: 0 10px">                require_once( ABSPATH . 'wp-admin/includes/media.php' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-               $this->create_tmp_dirs();
-               $this->unwrap_package();
-
-               add_filter( 'extra_plugin_headers', array( $this, 'extra_plugin_headers' ) );
</del><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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -87,85 +56,68 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return string Failure or success message.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function process_upload() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $plugin_files = $this->get_all_files( $this->plugin_dir );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $zip_file = $_FILES['zip_file']['tmp_name'];
+               $this->plugin_dir = Filesystem::unzip( $zip_file );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // First things first. Do we have something to work with?
-               if ( empty( $plugin_files ) ) {
-                       return __( 'The zip file was empty.', 'wporg-plugins' );
-               }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $plugin_files = Filesystem::list_files( $this->plugin_dir, true /* Recursive */, '!\.php$!i' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 foreach ( $plugin_files as $plugin_file ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! is_readable( $plugin_file ) ) {
-                               continue;
-                       }
-
</del><span class="cx" style="display: block; padding: 0 10px">                         $plugin_data = get_plugin_data( $plugin_file, false, false ); // No markup/translation needed.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $plugin_data['Name'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->plugin = $plugin_data;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                $this->plugin_root = dirname( $plugin_file );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 break;
</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><span class="cx" style="display: block; padding: 0 10px">                // Let's check some plugin headers, shall we?
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Catches both empty Plugin Name & when no valid files could be found.
+               if ( empty( $this->plugin['Name'] ) ) {
+                       $error = __( 'The plugin has no name.', 'wporg-plugins' );
</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 ( ! $this->plugin['Name'] ) {
-                       $error = __( 'The plugin has no name.', 'wporg-plugins' ) . ' ';
-
</del><span class="cx" style="display: block; padding: 0 10px">                         /* translators: 1: comment header line, 2: Codex URL */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $error .= sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%2$s">Plugin Headers</a>', 'wporg-plugins' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%2$s">Plugin Headers</a>', 'wporg-plugins' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 '<code>Plugin Name:</code>',
</span><span class="cx" style="display: block; padding: 0 10px">                                __( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' )
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       return $error;
</del><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">                // Determine the plugin slug based on the name of the plugin in the main plugin file.
</span><span class="cx" style="display: block; padding: 0 10px">                $this->plugin_slug = sanitize_title_with_dashes( $this->plugin['Name'] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->author      = wp_get_current_user();
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Make sure it doesn't use a slug deemed not to be used by the public.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $this->has_reserved_slug() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /* translators: 1: plugin slug, 2: style.css */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return sprintf( __( 'Sorry, the plugin name %1$s is reserved for use by WordPress Core. Please change the name of your plugin and upload it again.', 'wporg-plugins' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return sprintf( __( 'Sorry, the plugin name %1$s is reserved for use by WordPress. Please change the name of your plugin and upload it again.', 'wporg-plugins' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 '<code>' . $this->plugin_slug . '</code>'
</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">-                // Populate the plugin post and author.
-               $this->plugin_post = $this->get_plugin_post();
-
</del><span class="cx" style="display: block; padding: 0 10px">                 // Is there already a plugin with the name name?
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $this->plugin_post ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( Plugin_Directory::get_plugin_post( $this->plugin_slug ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         /* translators: 1: plugin slug, 2: style.css */
</span><span class="cx" style="display: block; padding: 0 10px">                        return sprintf( __( 'There is already a plugin called %1$s by a different author. Please change the name of your plugin and upload it again.', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                '<code>' . $this->plugin_slug . '</code>'
</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">-                $plugin_description = $this->strip_non_utf8( (string) $this->plugin['Description'] );
-               if ( empty( $plugin_description ) ) {
-                       $error = __( 'The plugin has no description.', 'wporg-plugins' ) . ' ';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $this->plugin['Description'] ) {
+                       $error = __( 'The plugin has no description.', 'wporg-plugins' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        /* translators: 1: comment header line, 2: style.css, 3: Codex URL */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $error .= sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%3$s">Plugin Headers</a>', 'wporg-plugins' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%3$s">Plugin Headers</a>', 'wporg-plugins' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 '<code>Description:</code>',
</span><span class="cx" style="display: block; padding: 0 10px">                                __( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' )
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       return $error;
</del><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">                if ( ! $this->plugin['Version'] ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $error = __( 'The plugin has no version.', 'wporg-plugins' ) . ' ';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $error = __( 'The plugin has no version.', 'wporg-plugins' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        /* translators: 1: comment header line, 2: style.css, 3: Codex URL */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $error .= sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%3$s">Plugin Headers</a>', 'wporg-plugins' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%3$s">Plugin Headers</a>', 'wporg-plugins' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 '<code>Version:</code>',
</span><span class="cx" style="display: block; padding: 0 10px">                                __( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' )
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       return $error;
</del><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">                if ( preg_match( '|[^\d\.]|', $this->plugin['Version'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -182,27 +134,33 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return __( 'Duplicate plugin and author URLs. A plugin URL is a page/site that provides details about this specific plugin. An author URL is a page/site that provides information about the author of the plugin. You aren&rsquo;t required to provide both, so pick the one that best applies to your URL.', '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">-                // Don't send special plugins through Plugin Check.
-               if ( ! has_category( 'special-case-plugin', $this->plugin_post ) ) {
-                       // Pass it through Plugin Check and see how great this plugin really is.
-                       $result = $this->check_plugin( $plugin_files );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Pass it through Plugin Check and see how great this plugin really is.
+               $result = $this->check_plugin();
</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 ( ! $result ) {
-                               /* translators: 1: Plugin Check Plugin URL, 2: make.wordpress.org/plugins */
-                               return sprintf( __( 'Your plugin has failed the plugin check. Please correct the problems with it and upload it again. You can also use the <a href="%1$s">Plugin Check Plugin</a> to test your plugin before uploading. If you have any questions about this please post them to %2$s.', 'wporg-plugins' ),
-                                       '//wordpress.org/plugins/plugin-check/',
-                                       '<a href="https://make.wordpress.org/plugins">https://make.wordpress.org/plugins</a>'
-                               );
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $result ) {
+                       /* translators: 1: Plugin Check Plugin URL, 2: make.wordpress.org/plugins */
+                       return sprintf( __( 'Your plugin has failed the plugin check. Please correct the problems with it and upload it again. You can also use the <a href="%1$s">Plugin Check Plugin</a> to test your plugin before uploading. If you have any questions about this please post them to %2$s.', 'wporg-plugins' ),
+                               '//wordpress.org/plugins/plugin-check/',
+                               '<a href="https://make.wordpress.org/plugins">https://make.wordpress.org/plugins</a>'
+                       );
</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">                // Passed all tests!
</span><span class="cx" style="display: block; padding: 0 10px">                // Let's save everything and get things wrapped up.
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Add a Plugin Directory entry for this plugin.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $post_id = $this->create_plugin_post();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $plugin_post = Plugin_Directory::create_plugin_post( array(
+                       'title'       => $this->plugin['Name'],
+                       'slug'        => $this->plugin_slug,
+                       'status'      => 'pending',
+                       'author'      => get_current_user_id(),
+                       'description' => $this->plugin['Description']
+               ) );
+               if ( is_wp_error( $plugin_post ) ) {
+                       return $plugin_post->get_error_message();
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $attachment = $this->save_zip_file( $post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $attachment = $this->save_zip_file( $plugin_post->ID );
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( is_wp_error( $attachment ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return $attachment->get_error_message();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,99 +168,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Send plugin author an email for peace of mind.
</span><span class="cx" style="display: block; padding: 0 10px">                $this->send_email_notification();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                do_action( 'plugin_upload', $this->plugin, $this->plugin_post );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         do_action( 'plugin_upload', $this->plugin, $plugin_post );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Success!
</span><span class="cx" style="display: block; padding: 0 10px">                /* translators: 1: plugin name */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px">                 return sprintf( __( 'Thank you for uploading %1$s to the WordPress Plugin Directory. We&rsquo;ve sent you an email verifying that we&rsquo;ve received it.', 'wporg-plugins' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->plugin['Name']
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 esc_html( $this->plugin['Name'] )
</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><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Creates a temporary directory, and the plugin dir within it.
-        */
-       public function create_tmp_dirs() {
-               // Create a temporary directory if it doesn't exist yet.
-               $tmp = '/tmp/wporg-plugin-upload';
-               if ( ! is_dir( $tmp ) ) {
-                       mkdir( $tmp, 0777 );
-               }
-
-               // Create file with unique file name.
-               $this->tmp_dir = tempnam( $tmp, 'WPORG_PLUGIN_' );
-
-               // Remove that file.
-               unlink( $this->tmp_dir );
-
-               // Create a directory with that unique name.
-               mkdir( $this->tmp_dir, 0777 );
-
-               // Get a sanitized name for that plugin and create a directory for it.
-               $base_name        = $this->get_sanitized_zip_name();
-               $this->plugin_dir = "{$this->tmp_dir}/{$base_name}";
-               mkdir( $this->plugin_dir, 0777 );
-
-               // Make sure we clean up after ourselves.
-               add_action( 'shutdown', array( $this, 'remove_files' ) );
-       }
-
-       /**
-        * Unzips the uploaded plugin and saves it in the temporary plugin dir.
-        */
-       public function unwrap_package() {
-               $unzip      = escapeshellarg( self::UNZIP );
-               $zip_file   = escapeshellarg( $_FILES['zip_file']['tmp_name'] );
-               $plugin_dir = escapeshellarg( $this->plugin_dir );
-
-               // Unzip it into the plugin directory.
-               exec( escapeshellcmd( "{$unzip} -DD {$zip_file} -d {$plugin_dir}" ) );
-
-               // Fix any permissions issues with the files. Sets 755 on directories, 644 on files.
-               exec( escapeshellcmd( "chmod -R 755 {$plugin_dir}" ) );
-               exec( escapeshellcmd( "find {$plugin_dir} -type f -print0" ) . ' | xargs -I% -0 chmod 644 %' );
-       }
-
-       /**
-        * Adds plugin headers that are expected in the directory.
-        *
-        * @param array $headers Additional plugin headers. Default empty array.
-        * @return array
-        */
-       public function extra_plugin_headers( $headers ) {
-               $headers['Tags'] = 'Tags';
-
-               return $headers;
-       }
-
-       /**
-        * Returns the the plugin post if it already exists in the repository.
-        *
-        * @return \WP_Post|null
-        */
-       public function get_plugin_post() {
-               $plugins = get_posts( array(
-                       'name'             => $this->plugin_slug,
-                       'posts_per_page'   => 1,
-                       'post_type'        => 'plugin',
-                       'orderby'          => 'ID',
-                       /*
-                        * Specify post stati so this query returns a result for draft plugins, even
-                        * if the uploading user doesn't have have the permission to view drafts.
-                        */
-                       'post_status'      => array( 'publish', 'pending', 'draft', 'future', 'trash', 'suspend' ),
-                       'suppress_filters' => false,
-               ) );
-
-               return current( $plugins );
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Whether the uploaded plugin uses a reserved slug.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Passes if the author happens to be `wordpressdotorg`.
-        *
</del><span class="cx" style="display: block; padding: 0 10px">          * @return bool
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function has_reserved_slug() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -319,26 +196,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'updated',
</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">-                return in_array( $this->plugin_slug, $reserved_slugs ) && 'wordpressdotorg' !== $this->author->user_login;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return in_array( $this->plugin_slug, $reserved_slugs );
</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><span class="cx" style="display: block; padding: 0 10px">         * Sends a plugin through Plugin Check.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param array $files All plugin files to check.
</del><span class="cx" style="display: block; padding: 0 10px">          * @return bool Whether the plugin passed the checks.
</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 check_plugin( $files ) {
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function check_plugin() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Run the checks.
</span><span class="cx" style="display: block; padding: 0 10px">                // @todo Include plugin checker.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // pass $this->plugin_root as the plugin root
</ins><span class="cx" style="display: block; padding: 0 10px">                 $result = true;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Display the errors.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $verdict = $result ? array( 'tc-pass', __( 'Pass', 'wporg-plugins' ) ) : array(
-                       'tc-fail',
-                       __( 'Fail', 'wporg-plugins' )
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $result ) {
+                       $verdict = array( 'pc-pass', __( 'Pass', 'wporg-plugins' ) );
+               } else {
+                       $verdict = array( 'pc-fail', __( 'Fail', 'wporg-plugins' ) );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 echo '<h4>' . sprintf( __( 'Results of Automated Plugin Scanning: %s', 'wporg-plugins' ), vsprintf( '<span class="%1$s">%2$s</span>', $verdict ) ) . '</h4>';
</span><span class="cx" style="display: block; padding: 0 10px">                echo '<ul class="tc-result">' . 'Result' . '</ul>';
</span><span class="cx" style="display: block; padding: 0 10px">                echo '<div class="notice notice-info"><p>' . __( 'Note: While the automated plugin scan is based on the Plugin Review Guidelines, it is not a complete review. A successful result from the scan does not guarantee that the plugin will pass review. All submitted plugins are reviewed manually before approval.', 'wporg-plugins' ) . '</p></div>';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -347,36 +225,13 @@
</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">-         * Creates a plugin post.
-        *
-        * @return int|\WP_Error The post ID on success. The value 0 or WP_Error on failure.
-        */
-       public function create_plugin_post() {
-               $upload_date = current_time( 'mysql' );
-
-               return wp_insert_post( array(
-                       'post_author'    => $this->author->ID,
-                       'post_title'     => $this->plugin['Name'],
-                       'post_name'      => $this->plugin_slug,
-                       'post_excerpt'   => $this->plugin['Description'],
-                       'post_date'      => $upload_date,
-                       'post_date_gmt'  => $upload_date,
-                       'comment_status' => 'closed',
-                       'ping_status'    => 'closed',
-                       'post_status'    => 'pending',
-                       'post_type'      => 'plugin',
-                       'tags_input'     => $this->plugin['Tags'],
-               ) );
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Saves zip file and attaches it to the plugin post.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param int $post_id Post ID.
</span><span class="cx" style="display: block; padding: 0 10px">         * @return int|\WP_Error Attachment ID or upload error.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function save_zip_file( $post_id ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $_FILES['zip_file']['name'] = wp_generate_password( 12 ) . '-' . $_FILES['zip_file']['name'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $_FILES['zip_file']['name'] = wp_generate_password( 12, false ) . '-' . $_FILES['zip_file']['name'];
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'site_option_upload_filetypes', array( $this, 'whitelist_zip_files' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'default_site_option_upload_filetypes', array( $this, 'whitelist_zip_files' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -395,7 +250,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function send_email_notification() {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /* translators: %s: plugin name */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $email_subject = sprintf( __( '[WordPress Plugins] New Plugin - %s', 'wporg-plugins' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $email_subject = sprintf( __( '[WordPress.org Plugins] New Plugin - %s', 'wporg-plugins' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         $this->plugin['Name']
</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">@@ -408,82 +263,22 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->plugin['Name']
</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">-                wp_mail( $this->author->user_email, $email_subject, $email_content, 'From: plugins@wordpress.org' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $user_email = wp_get_current_user()->user_email;
+
+               wp_mail( $user_email, $email_subject, $email_content, 'From: plugins@wordpress.org' );
</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">        // Helper
</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">-         * Returns a sanitized version of the uploaded zip file name.
-        *
-        * @return string
-        */
-       public function get_sanitized_zip_name() {
-               return preg_replace( '|\W|', '', strtolower( basename( $_FILES['zip_file']['name'], '.zip' ) ) );
-       }
-
-       /**
-        * Returns all (usable) files of a given directory.
-        *
-        * @param string $dir Path to directory to search.
-        *
-        * @return array All files within the passed directory.
-        */
-       public function get_all_files( $dir ) {
-               $files        = array();
-               $dir_iterator = new \RecursiveDirectoryIterator( $dir );
-               $iterator     = new \RecursiveIteratorIterator( $dir_iterator, \RecursiveIteratorIterator::SELF_FIRST );
-
-               foreach ( $iterator as $file ) {
-                       // Only return files that are no directory references or Mac resource forks.
-                       if ( $file->isFile() && ! in_array( $file->getBasename(), array(
-                                       '..',
-                                       '.'
-                               ) ) && ! stristr( $file->getPathname(), '__MACOSX' )
-                       ) {
-                               array_push( $files, $file->getPathname() );
-                       }
-               }
-
-               return $files;
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Whitelist zip files to be allowed to be uploaded to the media library.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param string $site_exts Whitelisted file extentions.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * As we only want to accept *.zip uploads, we specifically exclude all other types here.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @return string Whitelisted file extentions.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @return string Whitelisted ZIP filetypes.
</ins><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 whitelist_zip_files( $site_exts ) {
-               $file_extenstions   = explode( ' ', $site_exts );
-               $file_extenstions[] = 'zip';
-
-               return implode( ' ', array_unique( $file_extenstions ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function whitelist_zip_files() {
+               return 'zip';
</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">-        /**
-        * Deletes the temporary directory.
-        */
-       public function remove_files() {
-               $rm    = escapeshellarg( self::RM );
-               $files = escapeshellarg( $this->tmp_dir );
-
-               exec( escapeshellcmd( "{$rm} -rf {$files}" ) );
-       }
-
-       /**
-        * Strips invalid UTF-8 characters.
-        *
-        * Non-UTF-8 characters in plugin descriptions will causes blank descriptions in plugins.trac.
-        *
-        * @param string $string The string to be converted.
-        *
-        * @return string The converted string.
-        */
-       protected function strip_non_utf8( $string ) {
-               ini_set( 'mbstring.substitute_character', 'none' );
-
-               return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
-       }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryshortcodesclassuploadphp"></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.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.php     2016-02-26 07:49:53 UTC (rev 2639)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php       2016-02-26 07:52:43 UTC (rev 2640)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,11 +11,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload' ) && 'upload' === $_POST['action'] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( UPLOAD_ERR_OK === $_FILES['zip_file']['error'] ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        switch_to_blog( WPORG_PLUGIN_DIRECTORY_BLOGID );
</del><span class="cx" style="display: block; padding: 0 10px">                                         $uploader = new Upload_Handler;
</span><span class="cx" style="display: block; padding: 0 10px">                                        $message  = $uploader->process_upload();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        restore_current_blog();
-
</del><span class="cx" style="display: block; padding: 0 10px">                                 }  else {
</span><span class="cx" style="display: block; padding: 0 10px">                                        $message = __( 'Error in file upload.', 'wporg-plugins' );
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -37,7 +34,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        </form>
</span><span class="cx" style="display: block; padding: 0 10px">                <?php else : ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        <p><?php printf( __( 'Before you can upload a new plugin, <a href="%s">please log in</a>.', 'wporg-plugins' ), esc_url( 'https://login.wordpress.org/' ) ); ?>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        <p>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 </p>
</ins><span class="cx" style="display: block; padding: 0 10px">                 <?php endif;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorytoolsclassfilesystemphp"></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/tools/class-filesystem.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/tools/class-filesystem.php                              (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-filesystem.php        2016-02-26 07:52:43 UTC (rev 2640)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,116 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Tools;
+
+/**
+ * Various filesystem-related methods
+ *
+ * @package WordPressdotorg\Plugin_Directory\Tools
+ */
+class Filesystem {
+       const TMP_DIR = '/tmp/plugin-directory/';
+
+       /**
+        * Retrieve a unique temporary directory.
+        *
+        * The temporary directory returned will be removed upon script termination.
+        *
+        * @param string $prefix The prefix for the directory, 'hello-dolly' for example. Optional.
+        *
+        * @return string The temporary directory.
+        */
+       public static function temp_directory( $prefix = '' ) {
+               if ( ! is_dir( self::TMP_DIR ) ) {
+                       mkdir( self::TMP_DIR, 0777 );
+               }
+
+               // Generate a unique filename
+               $tmp_dir = tempnam( self::TMP_DIR, $prefix );
+
+               // Replace that filename with a directory
+               unlink( $tmp_dir );
+               mkdir( $tmp_dir, 0777 );
+
+               // Automatically remove this temporary directory on shutdown:
+               register_shutdown_function( array( __CLASS__, 'rmdir' ), $tmp_dir );
+
+               return $tmp_dir;
+       }
+
+       /**
+        * Extract a ZIP file to a directory.
+        *
+        * @param string $zip_file The ZIP file to extract.
+        * @param string $temp_directory The Directory to extract the ZIP to. Optional. Default: A Temporary directory.
+        *
+        * @return string The directory the ZIP was extracted to.
+        */
+       public static function unzip( $zip_file, $directory = '' ) {
+               if ( ! $directory ) {
+                       $directory = self::temp_directory( basename( $zip_file ) );
+               }
+               $esc_zip_file  = escapeshellarg( $zip_file );
+               $esc_directory = escapeshellarg( $directory );
+
+               // Unzip it into the plugin directory.
+               exec( "unzip -DD {$esc_zip_file} -d {$esc_directory}" );
+
+               // Fix any permissions issues with the files. Sets 755 on directories, 644 on files.
+               exec( "chmod -R 755 {$esc_directory}" );
+               exec( "find {$esc_directory} -type f -exec chmod 644 {} \;" );
+
+               return $directory;
+       }
+
+       /**
+        * Returns all (usable) files of a given directory.
+        *
+        * @param string $directory Path to directory to search.
+        * @param bool   $recursive Whether to recurse into subdirectories. Default: false.
+        * @param string $pattern   A regular expression to match files against. Optional.
+        *
+        * @return array All files within the passed directory.
+        */
+       public static function list_files( $directory, $recursive = false, $pattern = null ) {
+               if ( $recursive ) {
+                       $iterator = new \RecursiveIteratorIterator(
+                               new \RecursiveDirectoryIterator( $directory ),
+                               \RecursiveIteratorIterator::SELF_FIRST
+                       );
+               } else {
+                       $iterator = new \DirectoryIterator( $directory );
+               }
+
+               // If a regular expression was given, filter to that.
+               $filtered = empty( $pattern ) ? $iterator : new \RegexIterator( $iterator, $pattern );
+
+               $files = array();
+               foreach ( $filtered as $file ) {
+                       if ( ! $file->isFile() ) {
+                               continue;
+                       } elseif ( stristr( $file->getPathname(), '__MACOSX' ) ) {
+                               continue;
+                       }
+
+                       $files[] = $file->getPathname();
+               }
+
+               return $files;
+       }
+
+       /**
+        * Forcibly remove a directory recursively.
+        *
+        * @param string $dir The directory to remove.
+        *
+        * @return bool Whether the directory was removed..
+        */
+       public static function rmdir( $dir ) {
+               if ( ! trim( $dir, '/' ) ) {
+                       return;
+               }
+               exec( 'rm -rf ' . escapeshellarg( $dir ) );
+
+               return is_dir( $dir );
+       }
+
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-filesystem.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>