Changeset 1416 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/functions.php
- Timestamp:
- 03/19/2015 07:14:42 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/functions.php
r1409 r1416 129 129 130 130 /** 131 * Bootstraps found themes for the frontend JS handler.132 *133 * @return array134 */135 function wporg_themes_prepare_themes_for_js() {136 global $wp_query;137 138 include_once API_WPORGPATH . 'themes/info/1.0/class-themes-api.php';139 $api = new Themes_API( 'get_result' );140 $api->fields = array_merge( $api->fields, array(141 'description' => true,142 'sections' => false,143 'tested' => true,144 'requires' => true,145 'rating' => true,146 'ratings' => true,147 'downloaded' => true,148 'downloadlink' => true,149 'last_updated' => true,150 'homepage' => true,151 'tags' => true,152 'num_ratings' => true,153 'parent' => true,154 'theme_url' => true,155 ) );156 157 $themes = array_map( array( $api, 'fill_theme' ), $wp_query->posts );158 $themes = array_map( 'wporg_themes_ajax_prepare_theme', $themes );159 160 $request = array();161 if ( get_query_var( 'browse' ) ) {162 $request['browse'] = get_query_var( 'browse' );163 } else if ( $wp_query->is_tag() ) {164 $request['tag'] = (array) explode( '+', get_query_var( 'tag' ) );165 }166 else if ( $wp_query->is_search() ) {167 $request['search'] = get_query_var( 's' );168 }169 else if ( $wp_query->is_author() ) {170 $request['author'] = get_user_by( 'id', get_query_var( 'author' ) )->user_nicename;171 }172 else if ( $wp_query->is_singular( 'repopackage' ) ) {173 $request['theme'] = get_query_var( 'name' );174 }175 176 return array(177 'themes' => $themes,178 'request' => $request,179 'total' => $wp_query->found_posts,180 );181 }182 183 /**184 * @param object $args185 * @param string $action186 *187 * @return array188 */189 function wporg_themes_api_args( $args, $action ) {190 if ( in_array( $action, array( 'query_themes', 'theme_information' ) ) ) {191 $args->per_page = 30;192 $args->fields['parent'] = true;193 $args->fields['ratings'] = true;194 $args->fields['tags'] = true;195 $args->fields['theme_url'] = true;196 }197 198 return $args;199 }200 add_filter( 'themes_api_args', 'wporg_themes_api_args', 10, 2 );201 202 /**203 * Removes Core's built-in query-themes handler, so we can safely add ours later on.204 */205 function wporg_themes_remove_ajax_action() {206 remove_action( 'wp_ajax_query-themes', 'wp_ajax_query_themes', 1 );207 }208 add_action( 'wp_ajax_query-themes', 'wporg_themes_remove_ajax_action', -1 );209 210 /**211 * A recreation of Core's implementation without capability check, since there is nothing to install.212 */213 function wporg_themes_query_themes() {214 $request = wp_unslash( $_REQUEST['request'] );215 $request['fields'] = wp_parse_args( $request['fields'], array(216 'description' => true,217 'sections' => false,218 'tested' => true,219 'requires' => true,220 'rating' => true,221 'ratings' => true,222 'downloaded' => true,223 'downloadlink' => true,224 'last_updated' => true,225 'homepage' => true,226 'tags' => true,227 'num_ratings' => true,228 'parent' => true,229 'theme_url' => true,230 ) );231 $args = wp_parse_args( $request, array(232 'per_page' => 20,233 ) );234 235 include_once API_WPORGPATH . 'themes/info/1.0/class-themes-api.php';236 $api = new Themes_API( 'query_themes', $args );237 $api = $api->response;238 239 if ( is_wp_error( $api ) ) {240 wp_send_json_error();241 }242 243 foreach ( $api->themes as $key => $theme ) {244 $api->themes[ $key ] = wporg_themes_ajax_prepare_theme( $theme );245 }246 247 wp_send_json_success( $api );248 }249 add_action( 'wp_ajax_query-themes', 'wporg_themes_query_themes' );250 add_action( 'wp_ajax_nopriv_query-themes', 'wporg_themes_query_themes' );251 252 function wporg_themes_theme_info() {253 $request = wp_unslash( $_REQUEST['request'] );254 $request['fields'] = wp_parse_args( $request['fields'], array(255 'description' => true,256 'sections' => false,257 'tested' => true,258 'requires' => true,259 'rating' => true,260 'ratings' => true,261 'downloaded' => true,262 'downloadlink' => true,263 'last_updated' => true,264 'homepage' => true,265 'tags' => true,266 'num_ratings' => true,267 'parent' => true,268 'theme_url' => true,269 ) );270 271 include_once API_WPORGPATH . 'themes/info/1.0/class-themes-api.php';272 $api = new Themes_API( 'theme_information', $request );273 $api = $api->response;274 275 if ( empty( $api ) ) {276 wp_send_json_error();277 }278 279 $api = wporg_themes_ajax_prepare_theme( $api );280 281 wp_send_json_success( $api );282 }283 add_action( 'wp_ajax_theme-info', 'wporg_themes_theme_info' );284 add_action( 'wp_ajax_nopriv_theme-info', 'wporg_themes_theme_info' );285 286 function wporg_themes_ajax_prepare_theme( $theme ) {287 global $themes_allowedtags;288 if ( empty( $themes_allowedtags ) ) {289 $themes_allowedtags = array(290 'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),291 'abbr' => array( 'title' => array() ),292 'acronym' => array( 'title' => array() ),293 'code' => array(),294 'pre' => array(),295 'em' => array(),296 'strong' => array(),297 'div' => array(),298 'p' => array(),299 'ul' => array(),300 'ol' => array(),301 'li' => array(),302 'h1' => array(),303 'h2' => array(),304 'h3' => array(),305 'h4' => array(),306 'h5' => array(),307 'h6' => array(),308 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),309 );310 }311 312 $author = get_user_by( 'slug', $theme->author );313 $theme->author = new StdClass;314 foreach ( array( 'user_nicename', 'display_name' ) as $property ) {315 $theme->author->$property = get_the_author_meta( $property, $author->ID );316 }317 318 $theme->name = wp_kses( $theme->name, $themes_allowedtags );319 $theme->version = wp_kses( $theme->version, $themes_allowedtags );320 $theme->description = wp_kses( $theme->description, $themes_allowedtags );321 $theme->downloaded = number_format_i18n( $theme->downloaded );322 $theme->rating_text = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) );323 $theme->num_ratings = number_format_i18n( $theme->num_ratings );324 $theme->preview_url = set_url_scheme( $theme->preview_url );325 326 if ( preg_match( '/screenshot.(jpg|jpeg|png|gif)/', $theme->screenshot_url, $match ) ) {327 $theme->screenshot_url = sprintf( 'https://i0.wp.com/themes.svn.wordpress.org/%1$s/%2$s/%3$s',328 $theme->slug,329 $theme->version,330 $match[0]331 );332 }333 334 return $theme;335 }336 337 /**338 131 * Include view templates in the footer. 339 132 */
Note: See TracChangeset
for help on using the changeset viewer.