Changeset 1463
- Timestamp:
- 03/30/2015 04:37:50 AM (10 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php
r1454 r1463 616 616 $api = new Themes_API( 'get_result' ); 617 617 $api->fields = array_merge( $api->fields, array( 618 'description' => true, 619 'sections' => false, 620 'tested' => true, 621 'requires' => true, 622 'rating' => true, 623 'ratings' => true, 624 'downloaded' => true, 625 'downloadlink' => true, 626 'last_updated' => true, 627 'homepage' => true, 628 'tags' => true, 629 'num_ratings' => true, 630 'parent' => true, 631 'theme_url' => true, 618 'description' => true, 619 'sections' => false, 620 'tested' => true, 621 'requires' => true, 622 'rating' => true, 623 'ratings' => true, 624 'downloaded' => true, 625 'downloadlink' => true, 626 'last_updated' => true, 627 'homepage' => true, 628 'tags' => true, 629 'num_ratings' => true, 630 'parent' => true, 631 'theme_url' => true, 632 'extended_author' => true, 633 'photon_screenshots' => true, 632 634 ) ); 633 635 634 636 $themes = array_map( array( $api, 'fill_theme' ), $wp_query->posts ); 635 $themes = array_map( 'wporg_themes_ajax_prepare_theme', $themes );636 637 637 638 $request = array(); … … 657 658 ); 658 659 } 659 660 661 /**662 * Removes Core's built-in query-themes handler, so we can safely add ours later on.663 */664 function wporg_themes_remove_ajax_action() {665 remove_action( 'wp_ajax_query-themes', 'wp_ajax_query_themes', 1 );666 }667 add_action( 'wp_ajax_query-themes', 'wporg_themes_remove_ajax_action', -1 );668 669 /**670 * A recreation of Core's implementation without capability check, since there is nothing to install.671 */672 function wporg_themes_query_themes() {673 $request = wp_unslash( $_REQUEST['request'] );674 $request['fields'] = wp_parse_args( $request['fields'], array(675 'description' => true,676 'sections' => false,677 'tested' => true,678 'requires' => true,679 'rating' => true,680 'ratings' => true,681 'downloaded' => true,682 'downloadlink' => true,683 'last_updated' => true,684 'homepage' => true,685 'tags' => true,686 'num_ratings' => true,687 'parent' => true,688 'theme_url' => true,689 ) );690 $args = wp_parse_args( array(691 'per_page' => 15,692 ), $request);693 694 include_once API_WPORGPATH . 'themes/info/1.0/class-themes-api.php';695 $api = new Themes_API( 'query_themes', $args );696 $api = $api->response;697 698 if ( is_wp_error( $api ) ) {699 wp_send_json_error();700 }701 702 foreach ( $api->themes as $key => $theme ) {703 $api->themes[ $key ] = wporg_themes_ajax_prepare_theme( $theme );704 }705 706 wp_send_json_success( $api );707 }708 add_action( 'wp_ajax_query-themes', 'wporg_themes_query_themes' );709 add_action( 'wp_ajax_nopriv_query-themes', 'wporg_themes_query_themes' );710 711 function wporg_themes_theme_info() {712 $request = wp_unslash( $_REQUEST['request'] );713 $request['fields'] = wp_parse_args( $request['fields'], array(714 'description' => true,715 'sections' => false,716 'tested' => true,717 'requires' => true,718 'rating' => true,719 'ratings' => true,720 'downloaded' => true,721 'downloadlink' => true,722 'last_updated' => true,723 'homepage' => true,724 'tags' => true,725 'num_ratings' => true,726 'parent' => true,727 'theme_url' => true,728 ) );729 730 include_once API_WPORGPATH . 'themes/info/1.0/class-themes-api.php';731 $api = new Themes_API( 'theme_information', $request );732 $api = $api->response;733 734 if ( empty( $api ) ) {735 wp_send_json_error();736 }737 738 $api = wporg_themes_ajax_prepare_theme( $api );739 740 wp_send_json_success( $api );741 }742 add_action( 'wp_ajax_theme-info', 'wporg_themes_theme_info' );743 add_action( 'wp_ajax_nopriv_theme-info', 'wporg_themes_theme_info' );744 745 function wporg_themes_ajax_prepare_theme( $theme ) {746 global $themes_allowedtags;747 if ( empty( $themes_allowedtags ) ) {748 $themes_allowedtags = array(749 'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),750 'abbr' => array( 'title' => array() ),751 'acronym' => array( 'title' => array() ),752 'code' => array(),753 'pre' => array(),754 'em' => array(),755 'strong' => array(),756 'div' => array(),757 'p' => array(),758 'ul' => array(),759 'ol' => array(),760 'li' => array(),761 'h1' => array(),762 'h2' => array(),763 'h3' => array(),764 'h4' => array(),765 'h5' => array(),766 'h6' => array(),767 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),768 );769 }770 771 $author = get_user_by( 'slug', $theme->author );772 $theme->author = new StdClass;773 foreach ( array( 'user_nicename', 'display_name' ) as $property ) {774 $theme->author->$property = get_the_author_meta( $property, $author->ID );775 }776 777 $theme->name = wp_kses( $theme->name, $themes_allowedtags );778 $theme->version = wp_kses( $theme->version, $themes_allowedtags );779 $theme->description = wp_kses( $theme->description, $themes_allowedtags );780 $theme->downloaded = number_format_i18n( $theme->downloaded );781 $theme->rating_text = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) );782 $theme->num_ratings = number_format_i18n( $theme->num_ratings );783 $theme->preview_url = set_url_scheme( $theme->preview_url );784 785 if ( preg_match( '/screenshot.(jpg|jpeg|png|gif)/', $theme->screenshot_url, $match ) ) {786 $theme->screenshot_url = sprintf( 'https://i0.wp.com/themes.svn.wordpress.org/%1$s/%2$s/%3$s',787 $theme->slug,788 $theme->version,789 $match[0]790 );791 }792 793 return $theme;794 } -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/js/theme.js
r1453 r1463 320 320 // Send request to api.wordpress.org/themes 321 321 apiCall: function( request, paginated ) { 322 return wp.ajax.send( 'query-themes', { 322 323 var options = { 324 type: 'POST', 325 url: 'https://api.wordpress.org/themes/info/1.1/', 323 326 data: { 327 action: 'query_themes', 324 328 // Request data 325 329 request: _.extend({ … … 327 331 fields: { 328 332 description: true, 333 sections: false, 329 334 tested: true, 330 335 requires: true, 331 rating: true,332 336 downloaded: true, 333 337 downloadLink: true, 334 338 last_updated: true, 335 339 homepage: true, 336 num_ratings: true 340 theme_url: true, 341 parent: true, 342 tags: true, 343 rating: true, 344 ratings: true, 345 num_ratings: true, 346 extended_author: true, 347 photon_screenshots: true 337 348 } 338 349 }, request) … … 345 356 } 346 357 } 347 }); 358 }; 359 360 return $.Deferred( function( deferred ) { 361 $.ajax( options ).done( function( response ) { 362 deferred['resolveWith']( this, [ response ] ); 363 }).fail( function() { 364 deferred.rejectWith( this, arguments ); 365 }); 366 }).promise(); 367 348 368 } 349 369 });
Note: See TracChangeset
for help on using the changeset viewer.