<!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>[1349] sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php: Determine proper theme-slug and use it everywhere instead of relying on WP_Theme to give it to us, because WP_Theme returns the directory name.</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/1349">1349</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/1349","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>Otto42</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-02-27 18:03:24 +0000 (Fri, 27 Feb 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'>Determine proper theme-slug and use it everywhere instead of relying on WP_Theme to give it to us, because WP_Theme returns the directory name. This makes sense for WP_Theme in core, where the directory name is needed to find the theme, however here we need the sanitized version of the theme name to detemine the slug in the directory and in SVN.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclasswporgthemesuploadphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclasswporgthemesuploadphp"></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/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    2015-02-27 17:58:59 UTC (rev 1348)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php      2015-02-27 18:03:24 UTC (rev 1349)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -107,8 +107,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // We have a stylesheet, let's set up the theme, theme post, and author.
</span><span class="cx" style="display: block; padding: 0 10px">                $this->theme      = new WP_Theme( basename( dirname( $style_css ) ), dirname( dirname( $style_css ) ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->theme_post = $this->get_theme_post();
-               $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">                // We need a screen shot. People love screen shots.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! $this->has_screenshot( $theme_files ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -120,10 +118,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                
</span><span class="cx" style="display: block; padding: 0 10px">                // Let's check some theme headers, shall we?
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! $this->theme->get( 'Name' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $this->theme_name = $this->theme->get( 'Name' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return __( "The theme has no name. Add it to style.css and upload the theme again. <a href='https://codex.wordpress.org/Theme_Development#Theme_Style_Sheet'>Theme Style Sheets</a>", 'wporg-themes' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // determine the theme slug based on the name of the theme in the stylesheet
+               $this->theme_slug = sanitize_title_with_dashes( $this->theme_name );
+
+               // populate the theme post and author
+               $this->theme_post = $this->get_theme_post();
+               $this->author     = wp_get_current_user();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $theme_description = $this->strip_non_utf8( (string) $this->theme->get( 'Description' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                if ( empty( $theme_description ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        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' ), 'https://codex.wordpress.org/Theme_Development#Theme_Style_Sheet' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -143,7 +148,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Make sure we have version that is higher than any previously uploaded version of this theme.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $this->theme_post ) && ! version_compare( $this->theme->get( 'Version' ), $this->theme_post->max_version, '>' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        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>' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 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_post->max_version . '</code>' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Prevent duplicate URLs.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -158,12 +163,12 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        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>' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 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_slug . '</code>' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Is there already a theme with the name name by a different author?
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $this->theme_post ) && $this->theme_post->post_author != $this->author->ID ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        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>' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 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_slug . '</code>' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // We know it's the correct author, now we can check if it's suspended.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -275,7 +280,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_theme_post() {
</span><span class="cx" style="display: block; padding: 0 10px">                $themes = get_posts( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'name'             => $this->theme->get_stylesheet(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'name'             => $this->theme_slug,
</ins><span class="cx" style="display: block; padding: 0 10px">                         'posts_per_page'   => 1,
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_type'        => 'repopackage',
</span><span class="cx" style="display: block; padding: 0 10px">                        'orderby'          => 'ID',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -344,7 +349,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $slug = str_replace(
</span><span class="cx" style="display: block; padding: 0 10px">                        array( 'twenty-ten', 'twenty-eleven', 'twenty-twelve', 'twenty-thirteen', 'twenty-fourteen', 'twenty-fifteen', 'twenty-sixteen', 'twenty-seventeen', 'twenty-eighteen', 'twenty-nineteen', 'twenty-twenty' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        array( 'twentyten',  'twentyeleven',  'twentytwelve',  'twentythirteen',  'twentyfourteen',  'twentyfifteen',  'twentysixteen',  'twentyseventeen',  'twentyeighteen',  'twentynineteen',  'twentytwenty'  ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->theme->get_stylesheet()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->theme_slug
</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">                $reserved_slugs = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -402,7 +407,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Keywords
</span><span class="cx" style="display: block; padding: 0 10px">                $this->trac_ticket->keywords = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'theme-' . $this->theme->get_stylesheet(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'theme-' . $this->theme_slug,
</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">                $this->trac_ticket->parent_link = '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -437,7 +442,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Diff line.
</span><span class="cx" style="display: block; padding: 0 10px">                $this->trac_ticket->diff_line = '';
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $this->theme_post->max_version ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $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" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->trac_ticket->diff_line = "\n" . sprintf( __( 'Diff with previous version: %s', 'wporg-themes' ), "https://themes.trac.wordpress.org/changeset?old_path={$this->theme_slug}/{$this->theme_post->max_version}&new_path={$this->theme_slug}/{$this->theme->display( 'Version' )}\n" );
</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">                // Hacky way to prevent a problem with xml-rpc.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -449,14 +454,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> Theme URL - {$this->theme->display( 'ThemeURI' )}
</span><span class="cx" style="display: block; padding: 0 10px"> Author URL - {$this->theme->display( 'AuthorURI' )}
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-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
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+SVN - https://themes.svn.wordpress.org/{$this->theme_slug}/{$this->theme->display( 'Version' )}
+ZIP - https://wordpress.org/themes/download/{$this->theme_slug}.{$this->theme->display( 'Version' )}.zip?nostats=1
</ins><span class="cx" style="display: block; padding: 0 10px"> {$this->trac_ticket->parent_link}
</span><span class="cx" style="display: block; padding: 0 10px"> {$this->trac_ticket->diff_line}
</span><span class="cx" style="display: block; padding: 0 10px"> History:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-[[TicketQuery(format=table, keywords=~theme-{$this->theme->get_stylesheet()}, col=id|summary|status|resolution|owner)]]
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+[[TicketQuery(format=table, keywords=~theme-{$this->theme_slug}, col=id|summary|status|resolution|owner)]]
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-[[Image(https://themes.svn.wordpress.org/{$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}/{$this->theme->screenshot}, width=640)]]
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+[[Image(https://themes.svn.wordpress.org/{$this->theme_slug}/{$this->theme->display( 'Version' )}/{$this->theme->screenshot}, width=640)]]
</ins><span class="cx" style="display: block; padding: 0 10px"> TICKET;
</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">@@ -512,7 +517,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $post_args   = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_author'    => $this->author->ID,
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_title'     => $this->theme->get( 'Name' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'post_name'      => $this->theme->get_stylesheet(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'post_name'      => $this->theme_slug,
</ins><span class="cx" style="display: block; padding: 0 10px">                         'post_content'   => $this->theme->get( 'Description' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_parent'    => $this->theme->post_parent,
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_date'      => $upload_date,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -562,7 +567,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function add_to_svn() {
</span><span class="cx" style="display: block; padding: 0 10px">                $import_msg = empty( $this->theme_post ) ?  __( 'New theme: %1$s - %2$s', 'wporg-themes' ) : __( 'New version of %1$s - %2$s', 'wporg-themes' );
</span><span class="cx" style="display: block; padding: 0 10px">                $import_msg = escapeshellarg( sprintf( $import_msg, $this->theme->display( 'Name' ), $this->theme->display( 'Version' ) ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $svn_path   = escapeshellarg( "https://themes.svn.wordpress.org/{$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $svn_path   = escapeshellarg( "https://themes.svn.wordpress.org/{$this->theme_slug}/{$this->theme->display( 'Version' )}" );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $theme_path = escapeshellarg( $this->theme_dir );
</span><span class="cx" style="display: block; padding: 0 10px">                $svn        = escapeshellarg( self::SVN );
</span><span class="cx" style="display: block; padding: 0 10px">                $password   = escapeshellarg( THEME_DROPBOX_PASSWORD );
</span></span></pre>
</div>
</div>

</body>
</html>