<!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>[1111] sites/trunk/wordpress.org/public_html/wp-content/plugins: Theme Directory: Initial commit to meta.svn.</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/1111">1111</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/1111","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>obenland</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-01-09 01:14:23 +0000 (Fri, 09 Jan 2015)</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'>Theme Directory: Initial commit to meta.svn.

See <a href="http://meta.trac.wordpress.org/ticket/745">#745</a>.</pre>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclassrepopackagephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-repo-package.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclasstracphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-trac.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclasswporgthemesrepopackagephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-repo-package.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclasswporgthemesuploadphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectorythemedirectoryphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryuploadphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/upload.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclassrepopackagephp"></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/theme-directory/class-repo-package.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/theme-directory/class-repo-package.php                           (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-repo-package.php     2015-01-09 01:14:23 UTC (rev 1111)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,36 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Class Repo_Package
+ *
+ * Base class for interacting with posts of the repo package type.
+ */
+class Repo_Package {
+
+       /**
+        * Holds a WP_Post object representing this post.
+        *
+        * @var WP_Post
+        */
+       public $wp_post;
+
+       /**
+        * Construct a new Package for the given post ID or object.
+        *
+        * @param WP_Post|int $post
+        */
+       public function __construct( $post = 0 ) {
+               $this->init( $post );
+       }
+
+       /**
+        * Set up the post the for the given ID or object.
+        *
+        * @param WP_Post|int $post
+        */
+       public function init( $post = 0 ) {
+               if ( $post ) {
+                       $this->wp_post = get_post( $post );
+               }
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-repo-package.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svnexecutable"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:executable</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+*
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclasstracphp"></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/theme-directory/class-trac.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/theme-directory/class-trac.php                           (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-trac.php     2015-01-09 01:14:23 UTC (rev 1111)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,115 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+if ( ! class_exists( 'IXR_Client' ) ) {
+       include_once ABSPATH . WPINC . '/class-IXR.php';
+}
+
+/**
+ * Class Trac
+ */
+class Trac {
+
+       /**
+        * Client to talk to a passed Trac setup.
+        *
+        * @var IXR_Client
+        */
+       public $rpc;
+
+       /**
+        * Array key for the value containing ticket attributes.
+        */
+       const attributes = 3;
+
+       /**
+        * @param string $username
+        * @param string $password
+        * @param string $host
+        * @param string $path
+        * @param string $port
+        * @param bool   $ssl
+        */
+       function __construct( $username, $password, $host, $path, $port, $ssl = false ) {
+               $this->rpc = new IXR_Client( $host, $path, $port );
+
+               $this->rpc->headers['Authorization'] = 'Basic ' . base64_encode( $username . ':' . $password );
+               $this->rpc->ssl                      = $ssl;
+       }
+
+       /**
+        * Creates a new Trac ticket.
+        *
+        * @param string $subj
+        * @param string $desc
+        * @param array  $attr
+        * @return bool
+        */
+       function ticket_create( $subj, $desc, $attr = array() ) {
+               if ( empty( $attr ) ) {
+                       $attr = new IXR_Value( array(), 'struct' );
+               }
+               $ok = $this->rpc->query( 'ticket.create', $subj, $desc, $attr );
+               if ( ! $ok ) {
+                       // print_r( $this->rpc );
+                       return false;
+               }
+
+               return $this->rpc->getResponse();
+       }
+
+       /**
+        * Updates a Trac ticket.
+        *
+        * @param int    $id      Ticket ID.
+        * @param string $comment Comment text.
+        * @param array  $attr    Optional. Ticket attributes. Default: Empty array.
+        * @param bool   $notify  Optional. Whether to notify the author. Default: false.
+        * @return bool
+        */
+       function ticket_update( $id, $comment, $attr = array(), $notify = false ) {
+               if ( empty( $attr['_ts'] ) ) {
+                       $get         = $this->ticket_get( $id );
+                       $attr['_ts'] = $get[ self::attributes ]['_ts'];
+               }
+               if ( empty( $attr['action'] ) ) {
+                       $attr['action'] = 'leave';
+               }
+
+               $ok = $this->rpc->query( 'ticket.update', $id, $comment, $attr, $notify );
+               if ( ! $ok ) {
+                       return false;
+               }
+
+               return $this->rpc->getResponse();
+       }
+
+       /**
+        * Searches for a Trac ticket.
+        *
+        * @param string $search
+        * @return bool
+        */
+       function ticket_query( $search ) {
+               $ok = $this->rpc->query( 'ticket.query', $search );
+               if ( ! $ok ) {
+                       return false;
+               }
+
+               return $this->rpc->getResponse();
+       }
+
+       /**
+        * Gets a Trac ticket.
+        *
+        * @param int $id Ticket ID.
+        * @return array|bool [id, time_created, time_changed, attributes] or false on failure.
+        */
+       function ticket_get( $id ) {
+               $ok = $this->rpc->query( 'ticket.get', $id );
+               if ( ! $ok ) {
+                       return false;
+               }
+
+               return $this->rpc->getResponse();
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclasswporgthemesrepopackagephp"></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/theme-directory/class-wporg-themes-repo-package.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/theme-directory/class-wporg-themes-repo-package.php                              (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-repo-package.php        2015-01-09 01:14:23 UTC (rev 1111)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,74 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Class WPORG_Themes_Repo_Package
+ *
+ * The WPORG_Themes_Repo_Package class extends the base package class for theme-specific info.
+ * You can create one with new and pass it either a post or post id.
+ */
+class WPORG_Themes_Repo_Package extends Repo_Package {
+
+       /**
+        * Returns the screenshot URL for a theme.
+        *
+        * @return string
+        */
+       public function screenshot_url() {
+               $screen = $this->wp_post->_screenshot;
+               if ( ! $screen ) {
+                       $screen = sprintf( '//ts.w.org/wp-content/themes/%1$s/screenshot.png?ver=%2$s', $this->wp_post->post_name, $this->latest_version() );
+               }
+
+               return $screen;
+       }
+
+       /**
+        * Returns the latest version number for a theme.
+        *
+        * The latest published version, or the latest version for unpublished themes.
+        *
+        * @return int|string
+        */
+       public function latest_version() {
+               // If we're looking at themes awaiting approval, use the corresponding version.
+               if ( current_user_can( 'approve_themes' ) && isset( $_REQUEST['meta_key'] ) && '_has_pending_version' == $_REQUEST['meta_key'] ) {
+                       return get_post_meta( $this->wp_post->ID, '_has_pending_version', true );
+               }
+
+               $status = get_post_meta( $this->wp_post->ID, '_status', true );
+               uksort( $status, 'version_compare' );
+
+               // Find if there is a live version, and use that one.
+               $latest = array_search( 'live', $status );
+
+               // If none, just get the latest version.
+               if ( ! $latest ) {
+                       $versions = array_keys( $status );
+                       $latest   = array_pop( $versions );
+               }
+
+               return $latest;
+       }
+
+       /**
+        * Magic getter for a few handy variables.
+        *
+        * @param string $name
+        * @return int|string
+        */
+       public function __get( $name ) {
+               $version = $this->latest_version();
+               switch ( $name ) {
+                       case 'version' :
+                               return $version;
+                       case 'theme-url' :
+                               return $this->wp_post->_theme_url[ $version ];
+                       case 'author-url' :
+                               return $this->wp_post->_author_url[ $version ];
+                       case 'ticket' :
+                               return $this->wp_post->_ticket_id[ $version ];
+                       default:
+                               return $this->wp_post->$name;
+               }
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclasswporgthemesuploadphp"></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/theme-directory/class-wporg-themes-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/theme-directory/class-wporg-themes-upload.php                            (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php      2015-01-09 01:14:23 UTC (rev 1111)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,729 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Class WPORG_Themes_Upload
+ *
+ * Processes a theme upload.
+ */
+class WPORG_Themes_Upload {
+       /**
+        * Path to `svn` script.
+        *
+        * @var string
+        */
+       const SVN = '/usr/bin/svn';
+
+       /**
+        * Path to `rm` script.
+        *
+        * @var string
+        */
+       const RM = '/bin/rm';
+
+       /**
+        * Path to `unzip` script.
+        *
+        * @var string
+        */
+       const UNZIP = '/usr/bin/unzip';
+
+       /**
+        * Path to temporary directory.
+        *
+        * @var string
+        */
+       private $tmp_dir;
+
+       /**
+        * Path to temporary theme folder.
+        *
+        * @var string
+        */
+       private $theme_dir;
+
+       /**
+        * The uploaded theme.
+        *
+        * @var WP_Theme
+        */
+       private $theme;
+
+       /**
+        * The theme post if it already exists in the repository.
+        *
+        * @var WP_Post
+        */
+       private $theme_post;
+
+       /**
+        * The theme author (current user).
+        *
+        * @var WP_User
+        */
+       private $author;
+
+       /**
+        * Trac ticket information.
+        *
+        * @var object
+        */
+       private $trac_ticket;
+
+       /**
+        * A Trac instance to communicate with theme.trac.
+        *
+        * @var Trac
+        */
+       private $trac;
+
+       /**
+        * Get set up to run tests on the uploaded theme.
+        */
+       public function __construct() {
+               $this->create_tmp_dirs();
+               $this->unwrap_package();
+       }
+
+       /**
+        * Processes the theme upload.
+        *
+        * Runs various tests, creates Trac ticket, repopackage post, and saves the files to the SVN repo.
+        *
+        * @return string Failure or success message.
+        */
+       public function process_upload() {
+               $theme_files = $this->get_all_files( $this->theme_dir );
+
+               // First things first. Do we have something to work with?
+               if ( empty( $theme_files ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return __( 'The zip file was empty.', 'wporg-themes' );
+               }
+
+               // Do we have a stylesheet? Life is kind of pointless without.
+               $style_css = $this->get_style_css( $theme_files );
+               if ( empty( $style_css ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'The zip file must include a file named %s.', 'wporg-themes' ), '<code>style.css</code>' );
+               }
+
+               // We have a stylesheet, let's set up the theme, theme post, and author.
+               $this->theme      = new WP_Theme( basename( dirname( $style_css ) ), dirname( dirname( $style_css ) ) );
+               $this->theme_post = $this->get_theme_post();
+               $this->author     = wp_get_current_user();
+
+               // We need a screen shot. People love screen shots.
+               if ( ! $this->has_screen_shot( $theme_files ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'The zip file must include a file named %1$s or %2$s.', 'wporg-themes' ), '<code>screenshot.png</code>', '<code>screenshot.jpg</code>' );
+               }
+
+               // Let's check some theme headers, shall we?
+
+               if ( ! $this->theme->get( 'Name' ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return __( "The theme has no name. Add it to style.css and upload the theme again. <a href='http://codex.wordpress.org/Theme_Development#Theme_Style_Sheet'>Theme Style Sheets</a>", 'wporg-themes' );
+               }
+
+               $theme_description = $this->strip_non_utf8( (string) $this->theme->get( 'Description' ) );
+               if ( empty( $theme_description ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'The theme has no description. Add it to <code>style.css</code> and upload the theme again. <a href="%s">Theme Style Sheets</a>', 'wporg-themes' ), 'http://codex.wordpress.org/Theme_Development#Theme_Style_Sheet' );
+               }
+
+               if ( ! $this->theme->get( 'Tags' ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return __( 'The stylesheet has no tags. Add a Tags: line to your <code>style.css</code> file and upload the zip file again.', 'wporg-themes' );
+               }
+
+               if ( ! $this->theme->get( 'Version' ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return __( 'The stylesheet has no version. Add a Version: line to your <code>style.css</code> file and upload the zip file again.', 'wporg-themes' );
+               }
+
+               if ( preg_match( '|[^\d\.]|', $this->theme->get( 'Version' ) ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return __( 'Version strings can only contain numeric and period characters (like 1.2). Please fix your Version: line in <code>style.css</code> and upload your theme again.', 'wporg-themes' );
+               }
+
+               // Make sure we have version that is higher than any previously uploaded version of this theme.
+               if ( ! empty( $this->theme_post ) && ! version_compare( $this->theme->get( 'Version' ), $this->theme_post->max_version, '>' ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'You need to upload a version of %1$s higher than %2$s. Increase the theme version number in <code>style.css</code>, then upload your zip file again.', 'wporg-themes' ), $this->theme->display( 'Name' ), '<code>' . $this->theme->display( 'Version' ) . '</code>' );
+               }
+
+               // Prevent duplicate URLs.
+               if ( ! $this->theme->get( 'ThemeURI' ) && ! $this->theme->get( 'AuthorURI' ) && $this->theme->get( 'ThemeURI' ) == $this->theme->get( 'AuthorURI' ) ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return __( 'Duplicate theme and author URLs. A theme URL is a page/site the provides details about this specific theme. An author URL is a page/site that provides information about the author of the theme. You aren&rsquo;t required to provide both, so pick the one that best applies to your URL.', 'wporg-themes' );
+               }
+
+               // Check for child theme's parent in the directory (non-buddypress only)
+               if ( $this->theme->parent() && ! in_array( 'buddypress', $this->theme->get( 'Tags' ) ) && ! $this->is_parent_available() ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'There is no theme called %s in the directory. For child themes, you must use a parent theme that already exists in the directory.', 'wporg-themes' ), '<code>' . $this->theme->parent() . '</code>' );
+               }
+
+               // Make sure it doesn't use a slug deemed not to be used by the public.
+               if ( $this->has_reserved_slug() ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'Sorry, the theme name %s is reserved for use by WordPress Core. Please change the name of your theme in <code>style.css</code> and upload it again.', 'wporg-themes' ), '<code>' . $this->theme->get_stylesheet() . '</code>' );
+               }
+
+               // Is there already a theme with the name name by a different author?
+               if ( ! empty( $this->theme_post ) && $this->theme_post->post_author != $this->author->ID ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'There is already a theme called %s by a different author. Please change the name of your theme in <code>style.css</code> and upload it again.', 'wporg-themes' ), '<code>' . $this->theme->get_stylesheet() . '</code>' );
+               }
+
+               // We know it's the correct author, now we can check if it's suspended.
+               if ( 'trash' === $this->theme_post->post_status ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'This theme is suspended from the Theme Repository and it can&rsquo;t be updated. If you have any questions about this please contact %s.', 'wporg-themes' ), '<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a>' );
+               }
+
+               // Don't send special themes through Theme Check.
+               if ( ! has_category( 'special-case-theme', $this->theme_post ) ) {
+                       // Pass it through Theme Check and see how great this theme really is.
+                       $result = $this->check_theme( $theme_files );
+
+                       if ( ! $result ) {
+                               $this->remove_files( $this->tmp_dir );
+
+                               return sprintf( __( 'Your theme has failed the theme check. Please correct the problems with it and upload it again. You can also use the <a href="%1$s">Theme Check Plugin</a> to test your theme before uploading. If you have any questions about this please contact %2$s.', 'wporg-themes' ), '//wordpress.org/plugins/theme-check/', '<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a>' );
+                       }
+               }
+
+               // Passed all tests!
+               // Let's save everything and get things wrapped up.
+
+               // Get all Trac ticket information set up.
+               $this->prepare_trac_ticket();
+
+               // Talk to Trac and let them know about our new version. Or new theme.
+               $ticket_id = $this->create_or_update_trac_ticket();
+
+               // Temporarily disabled, until we hava a working Trac connection.
+               if ( false /* ! $ticket_id */ ) {
+                       $this->remove_files( $this->tmp_dir );
+
+                       return sprintf( __( 'There was an error creating a Trac ticket for your theme, please report this error to %s', 'wporg-themes' ), '<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a>' );
+               }
+
+               // Add a or update the Theme Directory entry for this theme.
+               $this->create_or_update_theme_post( $ticket_id );
+
+               // Create a new version in SVN.
+               $this->add_to_svn();
+
+               // Send theme author an email for peace of mind.
+               $this->send_email_notification( $ticket_id );
+
+               // Finally remove all temporary files.
+               $this->remove_files( $this->tmp_dir );
+
+               do_action( 'theme_upload', $this->theme );
+
+               // Success!
+               return sprintf( __( 'Thank you for uploading %1$s to the WordPress Theme Directory. We&rsquo;ve sent you an email verifying that we&rsquo;ve received it. Feedback will be provided at <a href="%2$s">%2$s</a>', 'wporg-themes' ), $this->theme->display( 'Name' ), esc_url( 'https://themes.trac.wordpress.org/ticket/' . $ticket_id ) );
+       }
+
+       /**
+        * Creates a temporary directory, and the theme dir within it.
+        */
+       public function create_tmp_dirs() {
+               // Create a temporary directory if it doesn't exist yet.
+               $tmp = '/tmp/wporg-theme-upload';
+               if ( ! is_dir( $tmp ) ) {
+                       mkdir( $tmp, 0777 );
+               }
+
+               // Create file with unique file name.
+               $this->tmp_dir = tempnam( $tmp, 'WPORG_THEME_' );
+
+               // 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 theme and create a directory for it.
+               $base_name       = $this->get_sanitized_zip_name();
+               $this->theme_dir = "{$this->tmp_dir}/{$base_name}";
+               mkdir( $this->theme_dir, 0777 );
+       }
+
+       /**
+        * Unzips the uploaded theme and saves it in the temporary theme dir.
+        */
+       public function unwrap_package() {
+               $base_name = $this->get_sanitized_zip_name();
+               $tmp_dir   = "{$this->tmp_dir}/{$base_name}.zip";
+
+               // Move the uploaded zip in the temporary directory.
+               move_uploaded_file( $_FILES['zip_file']['tmp_name'], $tmp_dir );
+
+               $unzip     = escapeshellarg( self::UNZIP );
+               $tmp_dir   = escapeshellarg( $tmp_dir );
+               $theme_dir = escapeshellarg( "{$this->theme_dir}/" );
+
+               // Unzip it into the theme directory.
+               exec( escapeshellcmd( "{$unzip} {$tmp_dir} -d {$theme_dir}" ) );
+       }
+
+       /**
+        * Find the first style.css file with the shortest path.
+        *
+        * @param array $theme_files
+        * @return string
+        */
+       public function get_style_css( $theme_files ) {
+               $stylesheets = preg_grep( '/style.css/', $theme_files );
+               usort( $stylesheets, array( $this, 'sort_by_string_length' ) );
+
+               return (string) array_pop( $stylesheets );
+       }
+
+       /**
+        * Returns the the theme post if it already exists in the repository.
+        *
+        * @return WP_Post|null
+        */
+       public function get_theme_post() {
+               $themes = get_posts( array(
+                       'name'             => $this->theme->get_stylesheet(),
+                       'posts_per_page'   => 1,
+                       'post_type'        => 'repopackage',
+                       'orderby'          => 'ID',
+                       'post_status'      => 'any',
+                       'suppress_filters' => false,
+               ) );
+
+               $theme = array_pop( $themes );
+
+               if ( ! empty( $theme ) ) {
+                       $theme = $this->populate_post_with_meta( $theme );
+               }
+
+               return $theme;
+       }
+
+       /**
+        * Find the first screen shot file with the shortest path.
+        *
+        * Also adds the file extension to the theme information object for later use.
+        *
+        * @param array $theme_files
+        * @return bool
+        */
+       public function has_screen_shot( $theme_files ) {
+               $screen_shots = preg_grep( '/screenshot.(jpg|jpeg|png|gif)/', $theme_files );
+               usort( $screen_shots, array( $this, 'sort_by_string_length' ) );
+
+               $screen_shot                  = array_pop( $screen_shots );
+               $this->theme->screen_shot_ext = pathinfo( $screen_shot, PATHINFO_EXTENSION );
+
+               return (bool) $screen_shot;
+       }
+
+       /**
+        * Whether the parent theme for this theme is available in the repository.
+        *
+        * @return bool
+        */
+       public function is_parent_available() {
+               $parent = get_posts( array(
+                       'fields'           => 'ids',
+                       'name'             => $this->theme->get_template(),
+                       'posts_per_page'   => 1,
+                       'post_type'        => 'repopackage',
+                       'orderby'          => 'ID',
+                       'suppress_filters' => false,
+               ) );
+
+               return ! empty( $parent );
+       }
+
+       /**
+        * Whether the uploaded theme uses a reserved slug.
+        *
+        * Passes if the author happens to be `wordpressdotorg`.
+        *
+        * @return bool
+        */
+       public function has_reserved_slug() {
+               $slug = str_replace(
+                       array( 'twenty-ten', 'twenty-eleven', 'twenty-twelve', 'twenty-thirteen', 'twenty-fourteen', 'twenty-fifteen', 'twenty-sixteen', 'twenty-seventeen', 'twenty-eighteen', 'twenty-nineteen', 'twenty-twenty' ),
+                       array( 'twentyten',  'twentyeleven',  'twentytwelve',  'twentythirteen',  'twentyfourteen',  'twentyfifteen',  'twentysixteen',  'twentyseventeen',  'twentyeighteen',  'twentynineteen',  'twentytwenty'  ),
+                       $this->theme->get_stylesheet()
+               );
+
+               // Reserve "twenty" names for wordpressdotorg.
+               $reserved_slugs = array(
+                       'twentyten', 'twentyeleven', 'twentytwelve','twentythirteen', 'twentyfourteen', 'twentyfifteen',
+                       'twentysixteen', 'twentyseventeen','twentyeighteen', 'twentynineteen', 'twentytwenty',
+               );
+
+               return in_array( $slug, $reserved_slugs ) && 'wordpressdotorg' !== $this->author->user_login;
+       }
+
+       /**
+        * Sends a theme through Theme Check.
+        *
+        * @param array $files All theme files to check.
+        * @return bool Whether the theme passed the checks.
+        */
+       public function check_theme( $files ) {
+               // Load the theme checking code.
+               if ( ! function_exists( 'run_themechecks' ) ) {
+                       include_once WP_PLUGIN_DIR . '/theme-check/checkbase.php';
+               }
+
+               list( $php_files, $css_files, $other_files ) = $this->separate_files( $files );
+
+               // Run the checks.
+               $result = run_themechecks( $php_files, $css_files, $other_files );
+
+               // Display the errors.
+               $verdict = $result ? array( 'tc-pass', __( 'Pass', 'wporg-themes' ) ) : array( 'tc-fail', __( 'Fail', 'wporg-themes' ) );
+               echo '<h4>' . sprintf( __( 'Results of Automated Theme Scanning: %s', 'wporg-themes' ), vsprintf( '<span class="%1$s">%2$s</span>', $verdict ) ) . '</h4>';
+               echo '<ul class="tc-result">' . display_themechecks() . '</ul>';
+               echo '<div class="notice notice-info"><p>' . __( 'Note: While the automated theme scan is based on the Theme Review Guidelines, it is not a complete review. A successful result from the scan does not guarantee that the theme will pass review. All submitted themes are reviewed manually before approval.', 'wporg-themes' ) . '</p></div>';
+
+               // Override some of the upload checks for child themes.
+               if ( !! $this->theme->parent() ) {
+                       $result = true;
+               }
+
+               return $result;
+       }
+
+       /**
+        * Sets up all Trac ticket information that we need later.
+        */
+       public function prepare_trac_ticket() {
+               $this->trac_ticket = new StdClass;
+
+               // todo - check trac xml-rpc, maybe data needs to be escaped before sending it there.
+               $this->trac_ticket->summary = sprintf( 'THEME: %1$s â€“ %2$s', $this->theme->display( 'Name' ), $this->theme->display( 'Version' ) );
+
+               // Keywords
+               $this->trac_ticket->keywords = array(
+                       'theme-' . $this->theme->get_stylesheet(),
+               );
+
+               $this->trac_ticket->parent_link = '';
+               if ( $this->theme->parent() ) {
+                       if ( in_array( 'buddypress', $this->theme->get( 'Tags' ) ) ) {
+                               $this->trac_ticket->keywords[] = 'buddypress';
+                       } else {
+                               $this->trac_ticket->keywords[]  = 'child-theme';
+                               $this->trac_ticket->keywords[]  = 'parent-' . $this->theme->get_template();
+                               $this->trac_ticket->parent_link = "Parent Theme: https://wordpress.org/themes/{$this->theme->get_template()}";
+                       }
+               }
+
+               if ( in_array( 'accessibility-ready', $this->theme->get( 'Tags' ) ) ) {
+                       $this->trac_ticket->keywords[] = 'accessibility-ready';
+               }
+
+               // Priority
+               $this->trac_ticket->priority = 'new theme';
+               if ( ! empty( $this->theme_post->_status ) ) {
+
+                       // Is this an update to an existing, approved theme?
+                       if ( 'live' === $this->theme_post->_status[ $this->theme_post->max_version ] ) {
+                               $this->trac_ticket->priority = 'theme update';
+
+                               // Apparently not, it must be a new upload for previously unapproved theme.
+                       } else {
+                               $this->trac_ticket->priority = 'previously reviewed';
+                       }
+               }
+
+               // Diff line.
+               $this->trac_ticket->diff_line = '';
+               if ( ! empty( $this->theme_post->max_version ) ) {
+                       $this->trac_ticket->diff_line = "\n" . sprintf( __( 'Diff with previous version: %s', 'wporg-themes' ), "https://themes.trac.wordpress.org/changeset?old_path={$this->theme->get_stylesheet()}/{$this->theme_post->max_version}&new_path={$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}\n" );
+               }
+
+               // Hacky way to prevent a problem with xml-rpc.
+               $this->trac_ticket->description = <<<TICKET
+{$this->theme->display( 'Name' )} - {$this->theme->display( 'Version' )}
+
+{$this->theme->display( 'Description' )}
+
+Theme URL - {$this->theme->display( 'ThemeURI' )}
+Author URL - {$this->theme->display( 'AuthorURI' )}
+
+SVN - https://themes.svn.wordpress.org/{$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}
+ZIP - https://wordpress.org/themes/download/{$this->theme->get_stylesheet()}.{$this->theme->display( 'Version' )}.zip?nostats=1
+{$this->trac_ticket->parent_link}
+{$this->trac_ticket->diff_line}
+History:
+[[TicketQuery(format=table, keywords=~theme-{$this->theme->get_stylesheet()}, col=id|summary|status|resolution|owner)]]
+
+[[Image(https://themes.svn.wordpress.org/{$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}/screenshot.{$this->theme->screen_shot_ext}, width=640)]]
+TICKET;
+       }
+
+       /**
+        * Updates an existing Trac ticket or creates a new one.
+        *
+        * @return bool|int Ticket ID on success, false on failure.
+        */
+       public function create_or_update_trac_ticket() {
+               // Set up a way to communicate with Trac.
+               if ( empty( $this->trac ) ) {
+                       if ( ! class_exists( 'Trac' ) ) {
+                               include_once plugin_dir_path( __FILE__ ) . 'class-trac.php';
+                       }
+
+                       $this->trac = new Trac( 'themetracbot', THEME_TRACBOT_PASSWORD, 'themes.trac.wordpress.org', '/login/xmlrpc', 443, true /* is_ssl() */ );
+               }
+
+               // If there's a previous version, and the most current version's status is either `new` or `pending`, we update.
+               if ( ! empty( $this->theme_post->max_version ) && in_array( $this->theme_post->_status[ $this->theme_post->max_version ], array( 'new', 'pending' ) ) ) {
+                       $ticket_id = (int) $this->theme_post->_tickets[ $this->theme_post->max_version ];
+                       $ticket    = $this->trac->ticket_get( $ticket_id );
+
+                       // Make sure the ticket has no resolution and is not approved (3 = ticket attributes).
+                       if ( empty( $ticket[3]['resolution'] ) && 'approved' !== $ticket[3]['status'] ) {
+                               $this->theme_post->_status[ $this->theme_post->max_version ] = 'old';
+                               update_post_meta( $this->theme_post->ID, '_status', $this->theme_post->_status );
+
+                               $result    = $this->trac->ticket_update( $ticket_id, $this->trac_ticket->description, array( 'summary' => $this->trac_ticket->summary ), true /* Trigger email notifications */ );
+                               $ticket_id = $result ? $ticket_id : false;
+                       }
+
+                       // In all other cases we create a new ticket.
+               } else {
+                       $ticket_id = $this->trac->ticket_create( $this->trac_ticket->summary, $this->trac_ticket->description, array(
+                               'type'      => 'theme',
+                               'keywords'  => implode( ', ', $this->trac_ticket->keywords ),
+                               'reporter'  => $this->author->user_login,
+                               'cc'        => $this->author->user_email,
+                               'priority'  => $this->trac_ticket->priority,
+                       ) );
+               }
+
+               return $ticket_id;
+       }
+
+       /**
+        * Creates or updates a theme post.
+        *
+        * @param int $ticket_id Trac ticket ID
+        */
+       public function create_or_update_theme_post( $ticket_id ) {
+               $upload_date = current_time( 'mysql' );
+               $post_args   = array(
+                       'post_author'    => $this->author->ID,
+                       'post_title'     => $this->theme->get( 'Name' ),
+                       'post_name'      => $this->theme->get_stylesheet(),
+                       'post_content'   => $this->theme->get( 'Description' ),
+                       'post_date'      => $upload_date,
+                       'comment_status' => 'closed',
+                       'ping_status'    => 'closed',
+                       'post_type'      => 'repopackage',
+                       'tags_input'     => $this->theme->get( 'Tags' ),
+               );
+
+               // If we already have a post, update it.
+               if ( ! empty( $this->theme_post ) ) {
+                       $post_args['ID'] = $this->theme_post->ID;
+
+                       $post_id = wp_update_post( $post_args );
+
+                       // Otherwise create it for this new theme.
+               } else {
+                       $post_id = wp_insert_post( $post_args );
+               }
+
+               // Finally, add post meta.
+               $post_meta   = array(
+                       '_theme_url'   => $this->theme->get( 'ThemeURI' ),
+                       '_author_url'  => $this->theme->get( 'AuthorURI' ),
+                       '_status'      => 'new',
+                       '_upload_date' => $upload_date,
+                       '_ticket_id'   => $ticket_id,
+               );
+
+               foreach ( $post_meta as $meta_key => $meta_value ) {
+                       $meta_data = array_filter( (array) get_post_meta( $post_id, $meta_key, true ) );
+                       $meta_data[ $this->theme->get( 'Version' ) ] = $meta_value;
+                       update_post_meta( $post_id, $meta_key, $meta_data );
+               }
+
+               // Discard versions that are awaiting review.
+               wporg_themes_update_version_status( $post_id, $this->theme->get( 'Version' ), 'new' );
+
+               // Add an additional row with the trac ticket ID, to make it possible to find the post by this ID later.
+               add_post_meta( $post_id, sanitize_key( '_trac_ticket_' . $this->theme->get( 'Version' ) ), $ticket_id );
+       }
+
+       /**
+        * Add theme files to SVN.
+        */
+       public function add_to_svn() {
+               $import_msg = empty( $this->theme_post ) ?  __( 'New theme: %1$s - %2$s', 'wporg-themes' ) : __( 'New version of %1$s - %2$s', 'wporg-themes' );
+               $import_msg = escapeshellarg( sprintf( $import_msg, $this->theme->display( 'Name' ), $this->theme->display( 'Version' ) ) );
+               $svn_path   = escapeshellarg( "https://themes.svn.wordpress.org/{$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}" );
+               $theme_path = escapeshellarg( $this->theme_dir );
+               $svn        = escapeshellarg( self::SVN );
+               $password   = escapeshellarg( THEME_DROPBOX_PASSWORD );
+
+               exec( escapeshellcmd( "{$svn} --non-interactive --username themedropbox --password {$password} --no-auto-props -m {$import_msg} import {$theme_path} {$svn_path}" ) );
+       }
+
+       /**
+        * Sends out an email confirmation to the theme's author.
+        *
+        * @param int $ticket_id Trac ticket ID
+        */
+       public function send_email_notification( $ticket_id ) {
+               if ( ! empty( $this->theme_post ) ) {
+                       $email_subject = sprintf( __( '[WordPress Themes] %1$s, new version %2$s', 'wporg-themes' ), $this->theme->display( 'Name' ), $this->theme->display( 'Version' ) );
+                       $email_content = sprintf( __( "Thank you for uploading version %s of %s.\n\nFeedback will be provided at %s\n\n--\nThe WordPress.org Themes Team\ntheme-reviewers@lists.wordpress.org", 'wporg-themes' ), $this->theme->display( 'Version' ), $this->theme->display( 'Name' ), 'https://themes.trac.wordpress.org/ticket/' . $ticket_id );
+               } else {
+                       $email_subject = sprintf( __( '[WordPress Themes] New Theme - %s', 'wporg-themes' ), $this->theme->display( 'Name' ) );
+                       $email_content = sprintf( __( "Thank you for uploading %s to the WordPress Theme Directory. If your theme is selected to be part of the directory we'll send a follow up email.\n\nFeedback will be provided at %s\n\n--\nThe WordPress.org Themes Team\ntheme-reviewers@lists.wordpress.org", 'wporg-themes' ), $this->theme->display( 'Name' ), 'https://themes.trac.wordpress.org/ticket/' . $ticket_id );
+               }
+
+               wp_mail( $this->author->user_email, $email_subject, $email_content, 'From: theme-reviewers@lists.wordpress.org' );
+       }
+
+       // Helper
+
+       /**
+        * 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;
+       }
+
+       /**
+        * Separates files in three buckets, PHP files, CSS files, and others.
+        *
+        * Most likely used in preparation for the Theme Check plugin.
+        *
+        * @param array $files Files to separate.
+        * @return array
+        */
+       public function separate_files( $files ) {
+               $php_files = $css_files = $other_files = array();
+
+               foreach ( $files as $file ) {
+                       // PHP files.
+                       if ( true === fnmatch( "*.php", $file ) ) {
+                               $php_files[ $file ] = php_strip_whitespace( $file );
+
+                               // CSS files.
+                       } else if ( true === fnmatch( "*.css", $file ) ) {
+                               $css_files[ $file ] = file_get_contents( $file );
+
+                               // All the rest.
+                       } else {
+                               $other_files[ $file ] = file_get_contents( $file );
+                       }
+               }
+
+               return array( $php_files, $css_files, $other_files );
+       }
+
+       /**
+        * Populates a theme post with its meta data.
+        *
+        * @param WP_Theme $theme
+        * @return WP_Theme
+        */
+       public function populate_post_with_meta( $theme ) {
+               foreach ( get_post_custom_keys( $theme->ID ) as $meta_key ) {
+                       $theme->$meta_key = get_post_meta( $theme->ID, $meta_key, true );
+
+                       if ( is_array( $theme->$meta_key ) ) {
+                               ksort( $theme->$meta_key, SORT_NATURAL );
+                       }
+               }
+
+               // Save the highest recorded version number.
+               $uploaded_versions  = array_keys( $theme->_status );
+               $theme->max_version = end( $uploaded_versions );
+
+               return $theme;
+       }
+
+       /**
+        * Deletes the passed files or directory.
+        *
+        * @param string $files
+        */
+       public function remove_files( $files ) {
+               $rm    = escapeshellarg( self::RM );
+               $files = escapeshellarg( $files );
+
+               exec( escapeshellcmd( "{$rm} -rf {$files}" ) );
+       }
+
+       /**
+        * Strips invalid UTF-8 characters.
+        *
+        * Non-UTF-8 characters in theme descriptions will causes blank descriptions in themes.trac.
+        *
+        * @param string $string The string to be converted.
+        * @return string The converted string.
+        */
+       private function strip_non_utf8( $string ) {
+               ini_set( 'mbstring.substitute_character', 'none' );
+
+               return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
+       }
+
+       /**
+        * Helper function to sort strings by their length, favoring the shorter one.
+        *
+        * @param string $a
+        * @param string $b
+        * @return int
+        */
+       private function sort_by_string_length( $a, $b ) {
+               return strlen( $b ) - strlen( $a );
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectorythemedirectoryphp"></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/theme-directory/theme-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/theme-directory/theme-directory.php                              (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php        2015-01-09 01:14:23 UTC (rev 1111)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,568 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/*
+Plugin Name: Theme Repository
+Plugin URI:
+Description: Transforms a WordPress site in The Official Theme Directory.
+Version: 0.1
+Author: wordpressdotorg
+Author URI: http://wordpress.org/
+Text Domain: wporg-themes
+License: GPLv2
+License URI: http://opensource.org/licenses/gpl-2.0.php
+*/
+
+// Load base repo package.
+include_once plugin_dir_path( __FILE__ ) . 'class-repo-package.php';
+
+// Load theme repo package.
+include_once plugin_dir_path( __FILE__ ) . 'class-wporg-themes-repo-package.php';
+
+// Load uploader.
+include_once plugin_dir_path( __FILE__ ) . 'upload.php';
+
+/**
+ * Things to change on activation.
+ */
+function wporg_themes_activate() {
+
+       // Give Editors the ability to approve a theme.
+       // Can be split to different roles in the future.
+       $admin = get_role( 'editor' );
+       $admin->add_cap( 'approve_themes' );
+}
+register_activation_hook( __FILE__, 'wporg_themes_activate' );
+
+/**
+ * Things to change on deactivation.
+ */
+function wporg_themes_deactivate() {
+       $admin = get_role( 'editor' );
+       $admin->remove_cap( 'approve_themes' );
+}
+register_deactivation_hook( __FILE__, 'wporg_themes_deactivate' );
+
+/**
+ * Initialize.
+ */
+function wporg_themes_init() {
+       load_plugin_textdomain( 'wporg-themes' );
+
+       $labels = array(
+               'name'               => __( 'Packages', 'wporg-themes' ),
+               'singular_name'      => __( 'Package', 'wporg-themes' ),
+               'add_new'            => __( 'Add New', 'wporg-themes' ),
+               'add_new_item'       => __( 'Add New Package', 'wporg-themes' ),
+               'edit_item'          => __( 'Edit Package', 'wporg-themes' ),
+               'new_item'           => __( 'New Package', 'wporg-themes' ),
+               'view_item'          => __( 'View Package', 'wporg-themes' ),
+               'search_items'       => __( 'Search Packages', 'wporg-themes' ),
+               'not_found'          => __( 'No packages found', 'wporg-themes' ),
+               'not_found_in_trash' => __( 'No packages found in Trash', 'wporg-themes' ),
+               'parent_item_colon'  => __( 'Parent Package:', 'wporg-themes' ),
+               'menu_name'          => __( 'Packages', 'wporg-themes' ),
+       );
+
+       $args = array(
+               'labels'              => $labels,
+               'hierarchical'        => false,
+               'description'         => __( 'A package', 'wporg-themes' ),
+               'supports'            => array( 'title', 'editor', 'author', 'custom-fields', 'page-attributes' ),
+               'taxonomies'          => array( 'category', 'post_tag', 'type' ),
+               'public'              => true,
+               'show_ui'             => true,
+               'show_in_menu'        => true,
+               'show_in_nav_menus'   => false,
+               'publicly_queryable'  => true,
+               'exclude_from_search' => false,
+               'has_archive'         => true,
+               'query_var'           => true,
+               'can_export'          => true,
+               'rewrite'             => true,
+               'capability_type'     => 'post',
+       );
+
+       // This is the base generic type for repo plugins.
+       if ( ! post_type_exists( 'repopackage' ) ) {
+               register_post_type( 'repopackage', $args );
+       }
+}
+add_action( 'init', 'wporg_themes_init' );
+
+/**
+ * Capability mapping for custom caps.
+ *
+ * @param array  $caps    Returns the user's actual capabilities.
+ * @param string $cap     Capability name.
+ * @param int    $user_id The user ID.
+ * @param array  $args    Adds the context to the cap. Typically the object ID.
+ * @return array
+ */
+function wporg_themes_map_meta_cap( $caps, $cap, $user_id, $args ) {
+       switch ( $cap ) {
+               case 'approve_theme':
+                       $caps[] = 'approve_themes';
+                       unset( $caps[ array_search( $cap, $caps ) ] );
+
+                       // Don't allow Admins to approve their own themes.
+                       if ( isset( $args[0] ) && get_post( $args[0] )->post_author == $user_id ) {
+                               $caps[] = 'do_not_allow';
+                       }
+                       break;
+       }
+
+       return $caps;
+}
+add_filter( 'map_meta_cap', 'wporg_themes_map_meta_cap', 10, 4 );
+
+/**
+ * Grabs theme review results from Trac and updates theme version number statuses accordingly.
+ *
+ * We're only checking for new results when on the edit screen for themes, and only for updates since the last time we
+ * checked.
+ */
+function wporg_themes_sync_review_results() {
+       if ( 'repopackage' != $GLOBALS['typenow'] || ! defined( 'THEME_TRACBOT_PASSWORD' ) ) {
+               return;
+       }
+
+       if ( ! class_exists( 'Trac' ) ) {
+               include_once plugin_dir_path( __FILE__ ) . 'class-trac.php';
+       }
+
+       $trac         = new Trac( 'themetracbot', THEME_TRACBOT_PASSWORD, 'themes.trac.wordpress.org', '/login/xmlrpc', 443, true );
+       $last_request = get_option( 'wporg-themes-last-trac-sync', strtotime( '-2 days' ) );
+
+       foreach ( array( 'live', 'not-approved' ) as $resolution ) {
+               // Get array of tickets.
+               $tickets = (array) $trac->ticket_query( add_query_arg( array(
+                       'status'     => 'closed',
+                       'resolution' => $resolution,
+                       'order'      => 'changetime',
+                       'changetime' => date( 'c', $last_request ),
+                       'desc'       => 1,
+               ) ) );
+
+               foreach ( $tickets as $ticket_id ) {
+                       // Get the theme associated with that ticket.
+                       $post_ids = get_posts( array(
+                               'fields'         => 'ids',
+                               'meta_query'     => array(
+                                       array(
+                                               'value'   => $ticket_id,
+                                               'compare' => 'IN',
+                                       ),
+                               ),
+                               'post_status'    => 'any',
+                               'posts_per_page' => - 1,
+                               'post_type'      => 'repopackage',
+                       ) );
+
+                       if ( empty( $post_ids ) ) {
+                               continue;
+                       }
+
+                       $post_id = array_pop( $post_ids );
+                       $version = array_search( $ticket_id, (array) get_post_meta( $post_id, '_ticket_id', true ) );
+                       if ( ! $version ) {
+                               continue;
+                       }
+
+                       // Bail if the the theme is not new.
+                       if ( 'new' != wporg_themes_get_version_status( $post_id, $version ) ) {
+                               continue;
+                       }
+
+                       // Approved themes:
+                       if ( 'live' == $resolution ) {
+                               wporg_themes_update_version_status( $post_id, $version, 'pending' );
+
+                       // Unapproved themes:
+                       } else {
+                               wporg_themes_update_version_status( $post_id, $version, 'old' );
+                       }
+               }
+       }
+
+       update_option( 'wporg-themes-last-trac-sync', time() );
+}
+add_action( 'load-edit.php', 'wporg_themes_sync_review_results' );
+
+/**
+ * Returns the status of a theme's version.
+ *
+ * @param int          $post_id Post ID.
+ * @param string       $version The theme version to get the status for.
+ * @return bool|string The version-specific meta value or False on failure.
+ */
+function wporg_themes_get_version_status( $post_id, $version ) {
+       $status = false;
+       $meta   = (array) get_post_meta( $post_id, '_status', true );
+
+       if ( ! empty( $meta[ $version ] ) ) {
+               $status = $meta[ $version ];
+       }
+
+       return $status;
+}
+
+/**
+ * Handles updating the status of theme versions.
+ *
+ * @param int       $post_id         Post ID.
+ * @param string    $current_version The theme version to update.
+ * @param string    $new_status      The status to update the current version to.
+ * @return int|bool Meta ID if the key didn't exist, true on successful update,
+ *                  false on failure.
+ */
+function wporg_themes_update_version_status( $post_id, $current_version, $new_status ) {
+       $meta = get_post_meta( $post_id, '_status', true );
+
+       switch ( $new_status ) {
+               // There can only be one version with these statuses:
+               case 'new':
+               case 'live':
+                       // Discard all previous versions with that status.
+                       foreach ( array_keys( $meta, $new_status ) as $version ) {
+                               if ( version_compare( $version, $current_version, '<' ) ) {
+                                       $meta[ $version ] = 'old';
+                               }
+                       }
+
+                       // Mark the current version appropriately.
+                       $meta[ $current_version ] = $new_status;
+                       break;
+
+               case 'pending':
+                       // Discard all previous pending versions.
+                       foreach ( array_keys( $meta, $new_status ) as $version ) {
+                               if ( version_compare( $version, $current_version, '<' ) ) {
+                                       $meta[ $version ] = 'old';
+                               }
+                       }
+
+                       // Mark the current version as pending.
+                       $meta[ $current_version ] = $new_status;
+
+                       // Register the pending version.
+                       update_post_meta( $post_id, '_has_pending_version', $current_version );
+                       break;
+
+               // Marking a version as Old, does not have repercussions on other versions.
+               case 'old':
+                       $meta[ $current_version ] = $new_status;
+                       break;
+       }
+
+       return update_post_meta( $post_id, '_status', $meta );
+}
+
+/**
+ * Use theme screen shot for post thumbnails.
+ *
+ * @param string $html
+ * @param int    $post_id
+ * @return string
+ */
+function wporg_themes_post_thumbnail_html( $html, $post_id ) {
+       $post = get_post( $post_id );
+       if ( 'repopackage' == $post->post_type ) {
+               $theme = new WPORG_Themes_Repo_Package( $post );
+               // no size because we only have one (unknown) image size, so the theme needs to size with css
+               $html = '<img src="' . $theme->screenshot_url() . '"/>';
+       }
+
+       return $html;
+}
+add_filter( 'post_thumbnail_html', 'wporg_themes_post_thumbnail_html', 10, 2 );
+
+/**
+ * Filters repopackages to only contain themes that are ready to be approved, when on the corresponding view.
+ *
+ * @param WP_Query $wp_query
+ * @return WP_Query
+ */
+function wporg_themes_filter_repopackages( $wp_query ) {
+       if ( 'edit.php' == $GLOBALS['pagenow'] && 'repopackage' == $GLOBALS['typenow'] && current_user_can( 'approve_theme' ) && ! empty( $_REQUEST['meta_key'] ) && '_has_pending_version' == $_REQUEST['meta_key'] ) {
+               $wp_query->set( 'meta_key', '_has_pending_version' );
+       }
+
+       return $wp_query;
+}
+add_filter( 'pre_get_posts', 'wporg_themes_filter_repopackages' );
+
+/**
+ * Adds a view for Themes awaiting approval.
+ *
+ * @param array $views
+ * @return array
+ */
+function wporg_themes_status_pending_view( $views ) {
+       $total_posts = count( get_posts(array(
+               'fields'         => 'ids',
+               'meta_key'       => '_has_pending_version',
+               'post_status'    => 'any',
+               'posts_per_page' => - 1,
+               'post_type'      => 'repopackage',
+       ) ) );
+
+       if ( current_user_can( 'approve_themes' ) && ! empty( $total_posts ) ) {
+               $class = '';
+               if ( isset( $_REQUEST['meta_key'] ) && '_has_pending_version' == $_REQUEST['meta_key'] ) {
+                       $class = ' class="current"';
+               }
+
+               $views['status_pending'] = "<a href='edit.php?post_type=repopackage&post_status=any&meta_key=_has_pending_version'$class>" . sprintf( _nx( 'Pending Approval <span class="count">(%s)</span>', 'Pending Approval <span class="count">(%s)</span>', $total_posts, 'posts', 'wporg-themes' ), number_format_i18n( $total_posts ) ) . '</a>';
+       }
+
+       return $views;
+}
+add_filter( 'views_edit-repopackage', 'wporg_themes_status_pending_view' );
+
+/**
+ * Adds an action to approve themes.
+ *
+ * @param array   $actions
+ * @param WP_Post $post
+ * @return array
+ */
+function wporg_themes_post_row_actions( $actions, $post ) {
+       if ( 'repopackage' == $post->post_type ) {
+               $before = array_slice( $actions, 0, - 1, true );
+               $after  = array_slice( $actions, - 1, 1, true );
+
+               if ( current_user_can( 'approve_theme', $post->ID ) && isset( $_REQUEST['meta_key'] ) && '_has_pending_version' == $_REQUEST['meta_key'] ) {
+                       $before['approve_theme'] = sprintf( '<a class="submit-approve_theme" title="%1$s" href="%2$s">%3$s</a>', esc_attr__( 'Approve this item', 'wporg-themes' ), esc_url( wporg_themes_get_approve_url( $post ) ), __( 'Approve', 'wporg-themes' ) );
+               }
+
+               $actions = array_merge( $before, $after );
+       }
+
+       return $actions;
+}
+add_filter( 'post_row_actions', 'wporg_themes_post_row_actions', 10, 2 );
+
+/**
+ * Action link to approve a theme version.
+ *
+ * @param WP_Post $post
+ * @return string URL
+ */
+function wporg_themes_get_approve_url( $post ) {
+       return wp_nonce_url( add_query_arg( 'action', 'approve', admin_url( sprintf( get_post_type_object( $post->post_type )->_edit_link, $post->ID ) ) ), "approve-post_{$post->ID}" );
+}
+
+/**
+ * Approve a theme version.
+ */
+function wporg_themes_approve_theme() {
+       if ( isset( $_GET['post'] ) ) {
+               $post_id = (int) $_GET['post'];
+       }
+
+       if ( ! $post_id ) {
+               wp_redirect( admin_url( 'edit.php' ) );
+               exit();
+       }
+
+       check_admin_referer( 'approve-post_' . $post_id );
+
+       $version = get_post_meta( $post_id, '_has_pending_version', true );
+
+       if ( ! $version ) {
+               wp_die( __( 'This item has already been approved.', 'wporg-themes' ) );
+       }
+
+       $post = get_post( $post_id );
+
+       if ( ! get_post_type_object( $post->post_type ) ) {
+               wp_die( __( 'Unknown post type.' ) );
+       }
+
+       if ( ! current_user_can( 'approve_theme', $post_id ) || 'repopackage' != $post->post_type ) {
+               wp_die( __( 'You are not allowed to approve this item.', 'wporg-themes' ) );
+       }
+
+       wporg_themes_update_version_status( $post_id, $version, 'live' );
+       delete_post_meta( $post_id, '_has_pending_version' );
+
+       $ticket_id = get_post_meta( $post_id, '_trac_ticket_' . $version, true );
+       if ( 'publish' == $post->post_status ) {
+               $email_subject  = sprintf( __( '[WordPress Themes] %1$s %2$s is now live', 'wporg-themes' ), $post->post_title, $version );
+               $email_content  = sprintf( __( 'Version %1$s of %2$s is now live at https://wordpress.org/themes/%3$s.', 'wporg-themes' ), $version, $post->post_title, $post->post_name ) . "\n\n";
+               $email_content .= sprintf( __( 'Any feedback items are at %s.', 'wporg-themes' ), "https://themes.trac.wordpress.org/ticket/$ticket_id" ) . "\n\n--\n";
+               $email_content .= __( 'The WordPress.org Themes Team', 'wporg' ) . "\n";
+               $email_content .= 'theme-reviewers@lists.wordpress.org';
+
+       } else {
+               $email_subject  = sprintf( __( '[WordPress Themes] %s has been approved!', 'wporg-themes' ), $post->post_title );
+               $email_content  = sprintf( __( 'Congratulations, your new theme %1$s is now available to the public at https://wordpress.org/themes/%2$s.', 'wporg-themes' ), $post->post_title, $post->post_name ) . "\n\n";
+               $email_content .= sprintf( __( 'Any feedback items are at %s.', 'wporg-themes' ), "https://themes.trac.wordpress.org/ticket/$ticket_id" ) . "\n\n--\n";
+               $email_content .= __( 'The WordPress.org Themes Team', 'wporg' ) . "\n";
+               $email_content .= 'theme-reviewers@lists.wordpress.org';
+       }
+
+       wp_mail( get_user_by( 'id', $post->post_author )->user_email, $email_subject, $email_content, 'From: theme-reviewers@lists.wordpress.org' );
+
+
+       // Update the theme's post status.
+       wp_update_post( array(
+               'ID'          => $post_id,
+               'post_status' => 'publish',
+       ) );
+
+       wp_redirect( add_query_arg( 'approved', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), wp_get_referer() ) ) );
+       exit();
+}
+add_filter( 'admin_action_approve', 'wporg_themes_approve_theme' );
+
+/**
+ * Prevents repopackages from being deleted.
+ *
+ * @param int $post_id
+ */
+function wporg_theme_no_delete_repopackage( $post_id ) {
+       if ( 'repopackage' == get_post( $post_id )->post_type ) {
+               wp_die( __( 'Repopackages can not be deleted.', 'wporg-themes' ), '', array(
+                       'back_link' => true,
+               ) );
+       }
+}
+add_filter( 'before_delete_post', 'wporg_theme_no_delete_repopackage' );
+
+/**
+ * Give the user feedback after approving a theme.
+ */
+function wporg_themes_admin_notices() {
+       if ( ! empty( $_GET['approved'] ) ) {
+               $approved = absint( $_GET['approved'] );
+               $message  = _n( '%s theme approved.', '%s themes approved.', $approved );
+               add_settings_error( 'wporg_themes', 'approved', sprintf( $message, $approved ), 'updated' );
+       }
+
+       // Display admin notices, if any.
+       settings_errors( 'wporg_themes' );
+}
+add_filter( 'admin_notices', 'wporg_themes_admin_notices' );
+
+/**
+ * Better view in the Packages screen.
+ *
+ * @param array $columns
+ * @return array
+ */
+function wporg_themes_repopackage_columns( $columns ) {
+       $columns = array_merge( $columns, array(
+               'version'    => __( 'Version', 'wporg-themes' ),
+               'theme-url'  => __( 'Theme URL', 'wporg-themes' ),
+               'author-url' => __( 'Author URL', 'wporg-themes' ),
+               'ticket'     => __( 'Ticket ID', 'wporg-themes' ),
+       ) );
+       unset( $columns['categories'] );
+
+       return $columns;
+}
+add_filter( 'manage_repopackage_posts_columns', 'wporg_themes_repopackage_columns' );
+
+/**
+ * Custom columns for the admin screen.
+ *
+ * @param string $column
+ * @param int    $post_id
+ */
+function wporg_themes_repopackage_custom_columns( $column, $post_id ) {
+       $theme = new WPORG_Themes_Repo_Package( $post_id );
+
+       switch ( $column ) {
+               case 'ticket':
+                       if ( $theme->ticket ) {
+                               printf( '<a href="%1$s">%2$s</a>', esc_url( 'https://themes.trac.wordpress.org/ticket/' . $theme->ticket ), '#' . $theme->ticket );
+                       }
+                       break;
+               case 'theme-url':
+               case 'author-url':
+                       echo make_clickable( $theme->$column );
+                       break;
+               default:
+                       echo $theme->$column;
+       }
+}
+add_action( 'manage_repopackage_posts_custom_column', 'wporg_themes_repopackage_custom_columns', 10, 2 );
+
+/**
+ * Meta box to choose which version is live.
+ */
+function wporg_themes_add_meta_box() {
+       add_meta_box(
+               'wporg_themes_versions',
+               __( 'Theme Versions', 'wporg-themes' ),
+               'wporg_themes_meta_box_callback',
+               'repopackage',
+               'side',
+               'high'
+       );
+}
+add_action( 'add_meta_boxes', 'wporg_themes_add_meta_box' );
+
+/**
+ * Displays the content of the `_status` meta box.
+ *
+ * @param WP_Post $post
+ */
+function wporg_themes_meta_box_callback( $post ) {
+       $versions = get_post_meta( $post->ID, '_status', true );
+
+       if ( empty( $versions ) ) {
+               return;
+       }
+
+       // Add an nonce field so we can check for it later.
+       wp_nonce_field( 'wporg_themes_meta_box', 'wporg_themes_meta_box_nonce' );
+
+       foreach ( $versions as $version => $status ) :
+               ?>
+               <p><?php echo $version; ?> -
+                       <select name="wporg_themes_status[<?php echo base64_encode( $version ); // base64 because version numbers don't work so well as parts of keys ?>]">
+                               <option value="new" <?php selected( $status, 'new' ); ?>><?php esc_html_e( 'New', 'wporg-themes' ); ?></option>
+                               <option value="live" <?php selected( $status, 'live' ); ?>><?php esc_html_e( 'Live', 'wporg-themes' ); ?></option>
+                               <option value="pending" <?php selected( $status, 'pending' ); ?>><?php esc_html_e( 'Pending', 'wporg-themes' ); ?></option>
+                               <option value="old" <?php selected( $status, 'old' ); ?>><?php esc_html_e( 'Old', 'wporg-themes' ); ?></option>
+                       </select>
+               </p>
+       <?php
+       endforeach;
+}
+
+/**
+ * Sanitizes and saves meta box settings.
+ *
+ * @param int $post_id
+ */
+function wporg_themes_save_meta_box_data( $post_id ) {
+       // All the safety checks.
+       if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
+               return;
+       }
+       if ( ! isset( $_POST['wporg_themes_meta_box_nonce'] ) ) {
+               return;
+       }
+       if ( ! wp_verify_nonce( $_POST['wporg_themes_meta_box_nonce'], 'wporg_themes_meta_box' ) ) {
+               return;
+       }
+       // TODO should this be a post type specific capability?
+       if ( ! current_user_can( 'edit_post', $post_id ) ) {
+               return;
+       }
+
+       $new_status = array();
+       foreach ( $_POST['wporg_themes_status'] as $version => $status ) {
+               // We could check of the passed status is valid, but wporg_themes_update_version_status() handles that beautifully.
+               $new_status[ base64_decode( $version ) ] = $status;
+       }
+       uksort( $new_status, 'version_compare' );
+
+       // Update the statuses.
+       foreach ( $new_status as $version => $status ) {
+               wporg_themes_update_version_status( $post_id, $version, $status );
+       }
+}
+add_action( 'save_post', 'wporg_themes_save_meta_box_data' );
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryuploadphp"></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/theme-directory/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/theme-directory/upload.php                               (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/upload.php 2015-01-09 01:14:23 UTC (rev 1111)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,87 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Registers the upload shortcode.
+ */
+function wporg_themes_upload_shortcode() {
+       add_shortcode( 'wporg-themes-upload', 'wporg_themes_render_upload_shortcode' );
+}
+add_action( 'init', 'wporg_themes_upload_shortcode' );
+
+/**
+ * Renders the upload shortcode.
+ */
+function wporg_themes_render_upload_shortcode() {
+       if ( ! defined( 'THEME_TRACBOT_PASSWORD' ) || ! defined( 'THEME_DROPBOX_PASSWORD' ) ) {
+               printf( '<!-- %s -->', 'Please define SVN and Trac passwords.' );
+               return;
+       }
+
+       if ( is_user_logged_in() ) :
+
+               if ( ! empty( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wporg-themes-upload' ) && 'upload' === $_POST['action'] ) {
+                       $message = wporg_themes_process_upload();
+
+                       if ( ! empty( $message ) ) {
+                               echo "<div class='notice notice-warning'><p>{$message}</p></div>\n";
+                       }
+               }
+       ?>
+               <h4><?php _e( 'Select your zipped theme file', 'wporg-themes' ); ?></h4>
+               <form enctype="multipart/form-data" id="upload_form" method="POST" action="">
+                       <?php wp_nonce_field( 'wporg-themes-upload' ); ?>
+                       <input type="hidden" name="action" value="upload"/>
+                       <input type="file" id="zip_file" name="zip_file" size="25"/>
+                       <input id="upload_button" class="button" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-themes' ); ?>"/>
+
+                       <p>
+                               <small><?php printf( __( 'Maximum allowed file size: %s', 'wporg-themes' ), esc_html( wporg_themes_get_max_allowed_file_size() ) ); ?></small>
+                       </p>
+               </form>
+       <?php else : ?>
+               <p><?php printf( __( 'Before you can upload a new theme, <a href="%s">please log in</a>.', 'wporg-themes' ), esc_url( 'https://wordpress.org/support/bb-login.php' ) ); ?><p>
+       <?php endif;
+}
+
+/**
+ * Returns a human readable version of the max allowed upload size.
+ *
+ * @return string The allowed file size.
+ */
+function wporg_themes_get_max_allowed_file_size() {
+       $upload_size_unit = wp_max_upload_size();
+       $byte_sizes       = array( 'KB', 'MB', 'GB' );
+
+       for ( $unit = - 1; $upload_size_unit > 1024 && $unit < count( $byte_sizes ) - 1; $unit++ ) {
+               $upload_size_unit /= 1024;
+       }
+       if ( $unit < 0 ) {
+               $upload_size_unit = $unit = 0;
+       } else {
+               $upload_size_unit = (int) $upload_size_unit;
+       }
+       return $upload_size_unit . $byte_sizes[ $unit ];
+}
+
+/**
+ * Runs basic checks and hands off to the upload processor.
+ *
+ * @return string Failure or success message.
+ */
+function wporg_themes_process_upload( ) {
+       if ( ! is_user_logged_in() ) {
+               return __( 'You must logged in to upload a new theme.', 'wporg-themes' );
+       }
+
+       if ( 0 !== $_FILES['zip_file']['error'] ) {
+               return __( 'Error in file upload.', 'wporg-themes' );
+       }
+
+       if ( ! class_exists( 'WPORG_Themes_Upload' ) ) {
+               include_once plugin_dir_path( __FILE__ ) . 'class-wporg-themes-upload.php';
+       }
+
+       $upload = new WPORG_Themes_Upload;
+
+       return $upload->process_upload();
+}
</ins></span></pre>
</div>
</div>

</body>
</html>