Making WordPress.org

Ticket #5995: 5995.patch

File 5995.patch, 6.5 KB (added by dufresnesteven, 4 years ago)
Line 
1Index: plugins/theme-directory/class-themes-api.php
2===================================================================
3--- plugins/theme-directory/class-themes-api.php (revision 11935)
4+++ plugins/theme-directory/class-themes-api.php (working copy)
5@@ -64,6 +64,7 @@
6 'requires' => false,
7 'requires_php' => false,
8 'trac_tickets' => false,
9+ 'patterns' => false,
10 );
11
12 /**
13@@ -894,6 +895,34 @@
14
15 }
16
17+ if ( $this->fields['patterns'] ) {
18+ $pattern_meta = get_post_meta( $theme->ID, '_patterns', true );
19+ $patterns_data = array();
20+
21+ if ( ! empty( $pattern_meta ) ) {
22+ switch_to_blog( 699 ); // Pattern Directory
23+
24+ $args = array(
25+ 'post_name__in' => $pattern_meta,
26+ 'post_type' => 'wporg-pattern',
27+ 'post_status' => 'publish',
28+ );
29+
30+ foreach ( get_posts( $args ) as $pattern_post ) {
31+ $p = array();
32+ $p['name'] = $pattern_post->post_title;
33+ $p['link'] = get_permalink( $pattern_post );
34+
35+ $patterns_data[] = $p;
36+ }
37+
38+ restore_current_blog();
39+ }
40+
41+ $phil->patterns = $patterns_data;
42+ }
43+
44 wp_cache_set( $cache_key, $phil, $this->cache_group, $this->cache_life );
45
46 return $phil;
47Index: plugins/theme-directory/class-wporg-themes-upload.php
48===================================================================
49--- plugins/theme-directory/class-wporg-themes-upload.php (revision 11935)
50+++ plugins/theme-directory/class-wporg-themes-upload.php (working copy)
51@@ -76,6 +76,13 @@
52 public $theme;
53
54 /**
55+ * The uploaded theme.json.
56+ *
57+ * @var WP_Theme_JSON
58+ */
59+ public $theme_json = null;
60+
61+ /**
62 * The theme slug being uploaded.
63 *
64 * @var string
65@@ -370,6 +377,9 @@
66 // We have a stylesheet, let's set up the theme, theme post, and author.
67 $this->theme = new WP_Theme( basename( dirname( $style_css ) ), dirname( dirname( $style_css ) ) );
68
69+ // Get Theme.json data if it exists
70+ $this->theme_json = $this->get_theme_json( $theme_files );
71+
72 // We need a screen shot. People love screen shots.
73 if ( ! $this->has_screenshot( $theme_files ) ) {
74 $style_errors->add(
75@@ -1299,6 +1309,10 @@
76 '_screenshot' => $this->theme->screenshot,
77 );
78
79+ if ( ! empty( $this->theme_json ) && $this->theme_json->get_patterns() ) {
80+ $post_meta[ '_patterns' ] = $this->theme_json->get_patterns();
81+ }
82+
83 // Store readme.txt data if present.
84 foreach ( $this->readme as $field => $data ) {
85 $post_meta[ "_{$field}" ] = $data;
86@@ -1865,4 +1879,27 @@
87
88 $send->send( '#themereview-firehose' );
89 }
90+
91+ /**
92+ * Returns WP_THEME_JSON information if it exists.
93+ *
94+ * @return WP_Theme_JSON|null
95+ */
96+ public function get_theme_json( $theme_files ) {
97+ $theme_json = preg_grep( '/theme.json/i', $theme_files );
98+
99+ if ( ! $theme_json ) {
100+ return null;
101+ }
102+
103+ $file_path = (string) array_pop( $theme_json );
104+
105+ $decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) );
106+
107+ if ( ! is_array( $decoded_file ) ) {
108+ return null;
109+ }
110+
111+ return new WP_Theme_JSON( $decoded_file, 'default' );
112+ }
113 }
114Index: plugins/theme-directory/theme-directory.php
115===================================================================
116--- plugins/theme-directory/theme-directory.php (revision 11935)
117+++ plugins/theme-directory/theme-directory.php (working copy)
118@@ -889,6 +889,7 @@
119 'active_installs' => true,
120 'requires' => true,
121 'requires_php' => true,
122+ 'patterns' => true,
123 );
124
125 $api_result = wporg_themes_query_api( 'query_themes', $request );
126@@ -930,6 +931,7 @@
127 'active_installs' => true,
128 'requires' => true,
129 'requires_php' => true,
130+ 'patterns' => true
131 )
132 ) );
133 }
134Index: themes/pub/wporg-themes/css/components/_main.scss
135===================================================================
136--- themes/pub/wporg-themes/css/components/_main.scss (revision 11935)
137+++ themes/pub/wporg-themes/css/components/_main.scss (working copy)
138@@ -563,6 +563,10 @@
139 font-size: 13px;
140 }
141
142+.theme-wrap .theme-patterns {
143+ font-size: 13px;
144+}
145+
146 .theme-wrap .theme-downloads .total-downloads {
147 color: #555;
148 font-size: 14px;
149Index: themes/pub/wporg-themes/js/theme.js
150===================================================================
151--- themes/pub/wporg-themes/js/theme.js (revision 11935)
152+++ themes/pub/wporg-themes/js/theme.js (working copy)
153@@ -355,6 +355,7 @@
154 photon_screenshots: true,
155 active_installs: true,
156 requires_php: true,
157+ patterns: true,
158 }
159 }, request);
160
161@@ -524,6 +525,11 @@
162 return '<a href="' + themes.data.settings.path + themes.router.baseUrl( 'tags/' + slug ) + '">' + translated_tag + '</a>';
163 }).join( ', ' );
164
165+ // Make patterns click-able and separated by a comma.
166+ data.patterns = _.map( data.patterns, function( pattern ) {
167+ return '<a href="'+ pattern.link + '">' + pattern.name + '</a>';
168+ }).join( ', ' );
169+
170 data.path = themes.data.settings.path;
171
172 // Active Installs text
173Index: themes/pub/wporg-themes/theme-single.php
174===================================================================
175--- themes/pub/wporg-themes/theme-single.php (revision 11935)
176+++ themes/pub/wporg-themes/theme-single.php (working copy)
177@@ -111,6 +111,24 @@
178 </div><!-- .theme-tags -->
179 <?php } ?>
180
181+ <?php if ( $theme->patterns ) { ?>
182+ <div class="theme-patterns">
183+ <h2><?php _e( 'Patterns:', 'wporg-themes' ); ?></h2>
184+ <div><?php
185+ $pattern_links = array();
186+
187+ foreach ( $theme->patterns as $pattern ) {
188+ $pattern_links[] = sprintf(
189+ "<a href='%s'>%s</a>",
190+ esc_url( $pattern['link'] ),
191+ esc_html( $pattern['name'] )
192+ );
193+ }
194+ echo implode( ', ', $pattern_links );
195+ ?>
196+ </div>
197+ </div><!-- .theme-patterns -->
198+ <?php } ?>
199+
200 <div class="theme-downloads">
201 </div><!-- .theme-downloads -->
202 </div>
203Index: themes/pub/wporg-themes/view-templates/theme-single.php
204===================================================================
205--- themes/pub/wporg-themes/view-templates/theme-single.php (revision 11935)
206+++ themes/pub/wporg-themes/view-templates/theme-single.php (working copy)
207@@ -79,6 +79,13 @@
208 </div><!-- .theme-tags -->
209 <# } #>
210
211+ <# if ( data.patterns ) { #>
212+ <div class="theme-patterns">
213+ <h3><?php _e( 'Patterns:', 'wporg-themes' ); ?></h3>
214+ <div>{{{ data.patterns }}}</div>
215+ </div><!-- .theme-patterns -->
216+ <# } #>
217+
218 <div class="theme-downloads">
219 <h3><?php _e( 'Downloads Per Day', 'wporg-themes' ); ?></h3>
220 <div id="theme-download-stats-{{data.id}}" class="chart"></div>