<!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>[2755] sites/trunk/wordpress.org/public_html/wp-content: Themes Directory: Open-source the `pre_get_posts` logic used by the Themes Directory & add logic to handle the domain not matching the home_url.</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/2755">2755</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/2755","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-03-17 05:39:02 +0000 (Thu, 17 Mar 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Themes Directory: Open-source the `pre_get_posts` logic used by the Themes Directory & add logic to handle the domain not matching the home_url.

This allows us to remove the 'placeholder' sites we use for the themes directory on internationalized sites (xx.wordpress.org/themes), and makes the query logic more transparent.

See <a href="http://meta.trac.wordpress.org/ticket/1630">#1630</a> (which this is the first part for)
See <a href="http://meta.trac.wordpress.org/ticket/1618">#1618</a> (Some work will still be needed to correctly trim the description)</pre>

<h3>Modified Paths</h3>
<ul>
<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>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesembedphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/embed.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesfunctionsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/functions.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesheaderphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/header.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesindexphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/index.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesrssphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/rss.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryquerymodificationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/query-modifications.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryquerymodificationsphp"></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/query-modifications.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/query-modifications.php                          (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/query-modifications.php    2016-03-17 05:39:02 UTC (rev 2755)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,134 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Correct the post type for theme queries to be "repopackage".
+ */
+function wporg_themes_pre_get_posts( $query ) {
+       if ( is_admin() ) {
+               return;
+       }
+
+       // Don't apply this to non-theme queries
+       if ( !empty( $query->query_vars['post_type'] ) && 'repopackage' != $query->query_vars['post_type'] ) {
+               return;
+       }
+       // Themes are never via pagename
+       if ( !empty( $query->query_vars['pagename'] ) ) {
+               return;
+       }
+
+       // Default to the featured view
+       if ( empty( $query->query ) ) {
+               $query->query_vars['browse'] = 'featured';
+       }
+
+       // From now on, always query themes.
+       $query->query_vars['post_type'] = 'repopackage';
+       if ( ! isset( $query->query_vars['browse'] ) ) {
+               $query->query_vars['browse'] = '';
+       }
+
+       // Force the browse query_var when querying for a users favorites
+       if ( !empty( $query->query_vars['favorites_user'] ) ) {
+               $query->query_vars['browse'] = 'favorites';
+       }
+
+       switch ( $query->query_vars['browse'] ) {
+               case 'new':
+                       $query->query_vars['orderby'] = 'ID';
+                       $query->query_vars['order'] = 'DESC';
+                       break;
+
+               case 'updated':
+                       $query->query_vars['orderby'] = 'modified';
+                       $query->query_vars['order'] = 'DESC';
+                       break;
+
+               case 'featured':
+                       // Pages > 1 don't exist.
+                       if ( isset( $query->query_vars['paged'] ) && $query->query_vars['paged'] > 1 ) {
+                               // Force a 404
+                               $query->query_vars['post__in'] = array( 0 );
+                       }
+
+                       $query->query_vars['orderby'] = 'RAND(' . date( 'Ymd' ) . ')';
+                       $query->query_vars['posts_per_page'] = $query->found_posts = 15;
+                       // Featured themes require it to have been updated within the last year, not the default 2.
+                       $query->query_vars['date_query']['recent_themes_only'] = array(
+                               'column' => 'post_modified_gmt',
+                               'after'  => date( 'Y-m-d', strtotime( '-1 year' ) )
+                       );
+                       $query->query_vars['no_found_rows'] = true;
+                       break;
+
+               case 'favorites':
+                       $favorites = array();
+
+                       if ( !empty( $query->query_vars['favorites_user'] ) ) {
+                               $user_id = ( new WP_User( $query->query_vars['favorites_user'] ) )->ID;
+                       } elseif ( is_user_logged_in() ) {
+                               $user_id = get_current_user_id();
+                       }
+
+                       if ( ! empty( $user_id ) ) {
+                               $favorites = array_filter( (array) get_user_meta( $user_id, 'theme_favorites', true ) );
+                       }
+
+                       if ( $favorites ) {
+                               $query->query_vars['post_name__in'] = $favorites;
+                       } else {
+                               // Force a 404
+                               $query->query_vars['post__in'] = array( 0 );
+                       }
+
+                       $query->query_vars['orderby'] = 'post_title';
+                       $query->query_vars['order'] = 'ASC';
+                       break;
+
+               case 'popular':
+                       // Only include themes that have existed for at least 2 weeks into the popular listing
+                       // This avoids cases where a new theme skews our popularity algorithms.
+                       $query->query_vars['date_query']['existing_themes_only'] = array(
+                               'column' => 'post_date_gmt',
+                               'before'  => date( 'Y-m-d', strtotime( '-2 weeks' ) )
+                       );
+
+                       // Sort by the popularity meta key
+                       $query->query_vars['meta_key'] = '_popularity';
+                       $query->query_vars['meta_type'] = 'DECIMAL';
+                       $query->query_vars['orderby'] = 'meta_value';
+                       break;
+       }
+
+       // Unless a specific theme, or author is being requested, limit results to the last 2 years.
+       if ( empty( $query->query_vars['name'] ) && empty( $query->query_vars['author_name'] ) && ! in_array( $query->query_vars['browse'], array( 'favorites', 'new', 'updated' ) ) ) {
+               $query->query_vars['date_query']['recent_themes_only'] = array(
+                       'column' => 'post_modified_gmt',
+                       'after'  => date( 'Y-m-d', strtotime( '-2 years' ) ),
+               );
+       }
+
+       // Prioritize translated themes for localized requests, except when viewing a specific ordered themes.
+       if ( 'en_US' !== get_locale() && ! in_array( $query->query_vars['browse'], array( 'favorites', 'new', 'updated' ) )  ) {
+               add_filter( 'posts_clauses', 'wporg_themes_prioritize_translated_posts_clauses' );
+       }
+
+}
+add_action( 'pre_get_posts', 'wporg_themes_pre_get_posts' );
+
+/**
+ * Filters SQL clauses, to prioritize translated themes.
+ *
+ * @param array $clauses
+ *
+ * @return array
+ */
+function wporg_themes_prioritize_translated_posts_clauses( $clauses ) {
+       global $wpdb;
+
+       $clauses['groupby']  = "{$wpdb->posts}.ID";
+       $clauses['join']    .= $wpdb->prepare( " LEFT JOIN language_packs AS l ON ( {$wpdb->posts}.post_name = l.domain AND l.active=1 AND l.type='theme' AND l.language=%s )", get_locale() );
+       $clauses['orderby']  = 'l.domain IS NOT NULL DESC, ' . $clauses['orderby'];
+
+       return $clauses;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/query-modifications.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectorythemedirectoryphp"></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/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      2016-03-16 20:48:33 UTC (rev 2754)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php        2016-03-17 05:39:02 UTC (rev 2755)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,31 +1,34 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-Plugin 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
-*/
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Plugin Name: Theme Repository
+ * Plugin URI: https://wordpress.org/themes/
+ * Description: Transforms a WordPress site in The Official Theme Directory.
+ * Version: 1.0
+ * Author: wordpressdotorg
+ * Author URI: http://wordpress.org/
+ * Text Domain: wporg-themes
+ * License: GPLv2
+ * License URI: http://opensource.org/licenses/gpl-2.0.php
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Load base repo package.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-include_once plugin_dir_path( __FILE__ ) . 'class-repo-package.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+include __DIR__ . '/class-repo-package.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Load theme repo package.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-include_once plugin_dir_path( __FILE__ ) . 'class-wporg-themes-repo-package.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+include __DIR__ . '/class-wporg-themes-repo-package.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Load uploader.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-include_once plugin_dir_path( __FILE__ ) . 'upload.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+include __DIR__ . '/upload.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Load Themes API adjustments.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-include_once plugin_dir_path( __FILE__ ) . 'themes-api.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+include __DIR__ . '/themes-api.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Load adjustments to the edit.php screen for repopackage posts.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-include_once plugin_dir_path( __FILE__ ) . 'admin-edit.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+include __DIR__ . '/admin-edit.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Load the query modifications needed for the directory.
+include __DIR__ . '/query-modifications.php';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Things to change on activation.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -147,8 +150,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Add the browse/* views
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        add_rewrite_tag( '%browse%', '(featured|popular|new|favorites)' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_rewrite_tag( '%browse%', '(featured|popular|new|updated|favorites)' );
</ins><span class="cx" style="display: block; padding: 0 10px">         add_permastruct( 'browse', 'browse/%browse%' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        add_rewrite_tag( '%favorites_user%', '([^/]+)' );
+       //add_permastruct( 'favorites_user', 'browse/favorites/%favorites_user%' ); // TODO: Implment in JS before enabling
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( ! defined( 'WPORG_THEME_DIRECTORY_BLOGID' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                define( 'WPORG_THEME_DIRECTORY_BLOGID', get_current_blog_id() );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -743,6 +748,31 @@
</span><span class="cx" style="display: block; padding: 0 10px">        return wporg_themes_get_themes_for_query();
</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">+function wporg_themes_theme_information( $slug ) {
+       return wporg_themes_query_api( 'theme_information', array(
+               'slug' => $slug,
+               'fields' => array(
+                       'description' => true,
+                       'sections' => false,
+                       'tested' => true,
+                       'requires' => true,
+                       'downloaded' => false,
+                       'downloadlink' => true,
+                       'last_updated' => true,
+                       'homepage' => true,
+                       'theme_url' => true,
+                       'parent' => true,
+                       'tags' => true,
+                       'rating' => true,
+                       'ratings' => true,
+                       'num_ratings' => true,
+                       'extended_author' => true,
+                       'photon_screenshots' => true,
+                       'active_installs' => true,
+               )
+       ) );
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Makes a query against api.wordpress.org/themes/info/1.0/ without making a HTTP call
</span><span class="cx" style="display: block; padding: 0 10px">  * Switches to the appropriate blog for the query.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -750,9 +780,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wporg_themes_query_api( $method, $args = array() ) {
</span><span class="cx" style="display: block; padding: 0 10px">        include_once API_WPORGPATH . 'themes/info/1.0/class-themes-api.php';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        switch_to_blog( WPORG_THEME_DIRECTORY_BLOGID );
</del><span class="cx" style="display: block; padding: 0 10px">         $api = new Themes_API( $method, $args );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        restore_current_blog();
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        return $api->response;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -965,13 +993,47 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_init', 'wporg_themes_maybe_schedule_daily_job' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Correct the post type for theme queries to be "repopackage". This fixes the post type for embeds.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filter the URLs to use the current localized domain name, rather than WordPress.org.
+ *
+ * The Theme Directory is available at multiple URLs (internationalised domains), this method allows
+ * for the one blog (a single blog_id) to be presented at multiple URLs yet have correct localised links.
+ *
+ * This method works in conjunction with a filter in sunrise.php, duplicated here for transparency:
+ *
+ * // Make the Plugin Directory available at /plugins/ on all rosetta sites.
+ * function wporg_themes_on_rosetta_domains( $site, $domain, $path, $segments ) {
+ *     // All non-rosetta networks define DOMAIN_CURRENT_SITE in wp-config.php
+ *     if ( ! defined( 'DOMAIN_CURRENT_SITE' ) && 'wordpress.org' != $domain && '/themes/' == substr( $path . '/', 0, 8 ) ) {
+ *          $site = get_blog_details( WPORG_THEME_DIRECTORY_BLOGID );
+ *          if ( $site ) {
+ *              $site = clone $site;
+ *              // 6 = The Rosetta network, this causes the site to be loaded as part of the Rosetta network
+ *              $site->site_id = 6;
+ *              return $site;
+ *          }
+ *     }
+ *
+ *     return $site;
+ * }
+ * add_filter( 'pre_get_site_by_path', 'wporg_themes_on_rosetta_domains', 10, 4 );
+ *
+ * @param string $url The URL to be localized.
+ * @return string
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wporg_themes_adjust_main_query( $query ) {
-       if ( $query->is_main_query() && $query->get( 'name' ) && ! $query->is_404() ) {
-               $query->query_vars['post_type'] = 'repopackage';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wporg_themes_rosetta_network_localize_url( $url ) {
+       static $localized_url = null;
+
+       if ( get_current_blog_id() != WPORG_THEME_DIRECTORY_BLOGID ) {
+               return $url;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-}
-add_action( 'pre_get_posts', 'wporg_themes_adjust_main_query');
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        if ( is_null( $localized_url ) ) {
+               $localized_url = 'https://' . preg_replace( '![^a-z.-]+!', '', $_SERVER['HTTP_HOST'] );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        return preg_replace( '!^[https]+://wordpress\.org!i', $localized_url, $url );
+}
+if ( 'wordpress.org' != $_SERVER['HTTP_HOST'] && defined( 'WPORG_THEME_DIRECTORY_BLOGID' ) ) {
+       add_filter( 'option_home',    'wporg_themes_rosetta_network_localize_url' );
+       add_filter( 'option_siteurl', 'wporg_themes_rosetta_network_localize_url' );
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryuploadphp"></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/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       2016-03-16 20:48:33 UTC (rev 2754)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/upload.php 2016-03-17 05:39:02 UTC (rev 2755)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -81,12 +81,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                include_once plugin_dir_path( __FILE__ ) . 'class-wporg-themes-upload.php';
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        switch_to_blog( WPORG_THEME_DIRECTORY_BLOGID );
-
</del><span class="cx" style="display: block; padding: 0 10px">         $upload = new WPORG_Themes_Upload;
</span><span class="cx" style="display: block; padding: 0 10px">        $message = $upload->process_upload();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        restore_current_blog();
-
</del><span class="cx" style="display: block; padding: 0 10px">         return $message;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesembedphp"></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/themes/pub/wporg-themes/embed.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/themes/pub/wporg-themes/embed.php        2016-03-16 20:48:33 UTC (rev 2754)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/embed.php  2016-03-17 05:39:02 UTC (rev 2755)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -28,14 +28,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> if ( have_posts() ) :
</span><span class="cx" style="display: block; padding: 0 10px">        while ( have_posts() ) : the_post();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // setup the theme variable
+               // note, $theme contains things like active installs and other data to be added eventually
+               $theme = wporg_themes_theme_information( $post->post_name );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // setup the theme variable
-
-       $themes = wporg_themes_get_themes_for_query();
-       $theme = $themes['themes'][0];
-
-       // note, $theme contains things like active installs and other data to be added eventually
-
</del><span class="cx" style="display: block; padding: 0 10px">         ?>
</span><span class="cx" style="display: block; padding: 0 10px">                <div <?php post_class( 'wp-embed' ); ?>>
</span><span class="cx" style="display: block; padding: 0 10px">                                <div class="wp-embed-featured-image rectangular">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,11 +42,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        <p class="wp-embed-heading">
</span><span class="cx" style="display: block; padding: 0 10px">                                <a href="<?php the_permalink(); ?>" target="_top">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        <?php the_title(); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 <?php echo esc_html( $theme->name ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px">                                 </a>
</span><span class="cx" style="display: block; padding: 0 10px">                        </p>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        <div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 <div class="wp-embed-excerpt"><?php echo wp_trim_words( $theme->description, 55 ); ?></div>
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        <?php
</span><span class="cx" style="display: block; padding: 0 10px">                        /**
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesfunctionsphp"></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/themes/pub/wporg-themes/functions.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/themes/pub/wporg-themes/functions.php    2016-03-16 20:48:33 UTC (rev 2754)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/functions.php      2016-03-17 05:39:02 UTC (rev 2755)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -128,22 +128,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'body_class', 'wporg_themes_body_class' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Prevent 404 responses when we've got a theme via the API.
- */
-function wporg_themes_prevent_404() {
-       global $wp_query;
-       if ( ! is_404() ) {
-               return;
-       }
-       $themes = wporg_themes_get_themes_for_query();
-       if ( $themes['total'] ) {
-               $wp_query->is_404 = false;
-               status_header( 200 );
-       }
-}
-add_filter( 'template_redirect', 'wporg_themes_prevent_404' );
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px">  * Overrides feeds to use a custom RSS2 feed which contains the current requests themes.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wporg_themes_custom_feed() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -251,5 +235,5 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px">        return $template;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter('embed_template', 'wporg_themes_embed_template');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'embed_template', 'wporg_themes_embed_template' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesheaderphp"></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/themes/pub/wporg-themes/header.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/themes/pub/wporg-themes/header.php       2016-03-16 20:48:33 UTC (rev 2754)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/header.php 2016-03-17 05:39:02 UTC (rev 2755)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,7 +5,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @package wporg-themes
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-$GLOBALS['themes']    = wporg_themes_get_themes_for_query();
</del><span class="cx" style="display: block; padding: 0 10px"> $GLOBALS['pagetitle'] = __( 'Theme Directory &mdash; Free WordPress Themes', 'wporg-themes' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> require WPORGPATH . 'header.php';
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesindexphp"></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/themes/pub/wporg-themes/index.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/themes/pub/wporg-themes/index.php        2016-03-16 20:48:33 UTC (rev 2754)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/index.php  2016-03-17 05:39:02 UTC (rev 2755)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,14 +11,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @package wporg-themes
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-global $themes;
-
</del><span class="cx" style="display: block; padding: 0 10px"> get_header();
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px">        <div id="themes" class="wrap">
</span><span class="cx" style="display: block; padding: 0 10px">                <div class="wp-filter">
</span><span class="cx" style="display: block; padding: 0 10px">                        <div class="filter-count">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                <span class="count theme-count"><?php echo number_format_i18n( $themes['total'] ); ?></span>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         <span class="count theme-count"><?php echo number_format_i18n( $wp_query->found_posts ); ?></span>
</ins><span class="cx" style="display: block; padding: 0 10px">                         </div>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        <ul class="filter-links">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,26 +64,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        <div class="themes">
</span><span class="cx" style="display: block; padding: 0 10px">                                <?php
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( get_query_var('name') && !is_404() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        $theme = reset( $themes['themes'] );
-                                       include __DIR__ . '/theme-single.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 while ( have_posts() ) {
+                                               the_post();
+                                               $theme = wporg_themes_theme_information( $post->post_name );
+                                               include __DIR__ . '/theme-single.php';
+                                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                                 } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        foreach ( $themes['themes'] as $theme ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 while ( have_posts() ) {
+                                               the_post();
+                                               $theme = wporg_themes_theme_information( $post->post_name );
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 include __DIR__ . '/theme.php';
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                        // Add the navigation between pages
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( $themes['pages'] > 1 ) {
-                                               echo '<nav class="posts-navigation">';
-                                               echo paginate_links( array(
-                                                       'total' => $themes['pages'],
-                                                       'mid_size' => 3,
-                                               ) );
-                                               echo '</nav>';
-                                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 echo '<nav class="posts-navigation">';
+                                       echo paginate_links( array(
+                                               'mid_size' => 3,
+                                       ) );
+                                       echo '</nav>';
</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">                        </div>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        <?php /* TODO: Don't display this for no-js queries where $wp_query->post_count > 0, but JS needs it too. */ ?>
</ins><span class="cx" style="display: block; padding: 0 10px">                         <p class="no-themes"><?php _e( 'No themes found. Try a different search.', 'wporg-themes' ); ?></p>
</span><span class="cx" style="display: block; padding: 0 10px">                </div>
</span><span class="cx" style="display: block; padding: 0 10px">                <div class="theme-install-overlay"></div>
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgthemesrssphp"></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/themes/pub/wporg-themes/rss.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/themes/pub/wporg-themes/rss.php  2016-03-16 20:48:33 UTC (rev 2754)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/rss.php    2016-03-17 05:39:02 UTC (rev 2755)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -20,8 +20,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">        <sy:updateFrequency>1</sy:updateFrequency>
</span><span class="cx" style="display: block; padding: 0 10px">        <?php
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $themes = wporg_themes_get_themes_for_query();
-       foreach ( $themes['themes'] as $theme ) :
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ while ( have_posts() ) :
+               the_post();
+               $theme = wporg_themes_theme_information( $post->post_name );
</ins><span class="cx" style="display: block; padding: 0 10px">         ?>
</span><span class="cx" style="display: block; padding: 0 10px">        <item>
</span><span class="cx" style="display: block; padding: 0 10px">                <title><?php echo esc_html( $theme->name ); ?></title>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -35,6 +36,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                <description><![CDATA[<?php echo esc_html( $theme->description ); ?>]]></description>
</span><span class="cx" style="display: block; padding: 0 10px">                <content:encoded><![CDATA[<?php echo esc_html( $theme->description ); ?>]]></content:encoded>
</span><span class="cx" style="display: block; padding: 0 10px">        </item>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        <?php endforeach; ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php endwhile; ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> </channel>
</span><span class="cx" style="display: block; padding: 0 10px"> </rss>
</span><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>