Changeset 3511
- Timestamp:
- 06/20/2016 05:34:18 PM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php
r3225 r3511 2 2 namespace WordPressdotorg\Plugin_Directory; 3 3 use WordPressdotorg\Plugin_Directory\Tools; 4 4 5 /** 5 6 * Manages the capabilities for the WordPress.org plugins directory. … … 11 12 /** 12 13 * Filters a user's capabilities depending on specific context and/or privilege. 14 * 15 * @static 13 16 * 14 17 * @param array $required_caps Returns the user's actual capabilities. … … 72 75 } 73 76 77 /** 78 * Sets up custom roles and makes them available. 79 * 80 * @static 81 */ 74 82 public static function add_roles() { 75 83 $committer = array( 76 'read' => true,84 'read' => true, 77 85 'plugin_dashboard_access' => true, 78 'plugin_edit_own' => true,79 'plugin_set_category' => true,80 'plugin_add_committer' => true,81 'plugin_edit_others' => true,86 'plugin_edit_own' => true, 87 'plugin_set_category' => true, 88 'plugin_add_committer' => true, 89 'plugin_edit_others' => true, 82 90 ); 83 91 84 92 $reviewer = array_merge( $committer, array( 85 'moderate_comments' => true,93 'moderate_comments' => true, 86 94 'plugin_edit_pending' => true, 87 'plugin_review' => true,95 'plugin_review' => true, 88 96 ) ); 89 97 90 98 $admin = array_merge( $reviewer, array( 91 'plugin_approve' => true,92 'plugin_reject' => true,93 'plugin_disable' => true,94 'plugin_close' => true,99 'plugin_approve' => true, 100 'plugin_reject' => true, 101 'plugin_disable' => true, 102 'plugin_close' => true, 95 103 'plugin_set_section' => true, // Special categories. 96 'manage_categories' => true, // Let them assign these special categories.104 'manage_categories' => true, // Let them assign these special categories. 97 105 ) ); 98 106 99 107 // Remove the roles first, incase we've changed the permission set. 100 108 remove_role( 'plugin_committer' ); 101 remove_role( 'plugin_reviewer' );102 remove_role( 'plugin_admin' );109 remove_role( 'plugin_reviewer' ); 110 remove_role( 'plugin_admin' ); 103 111 add_role( 'plugin_committer', 'Plugin Committer', $committer ); 104 add_role( 'plugin_reviewer', 'Plugin Reviewer', $reviewer );105 add_role( 'plugin_admin', 'Plugin Admin', $admin );112 add_role( 'plugin_reviewer', 'Plugin Reviewer', $reviewer ); 113 add_role( 'plugin_admin', 'Plugin Admin', $admin ); 106 114 107 foreach ( array( 'contributor', 'author', 'editor', 'administrator' ) as $role ) {115 foreach ( array( 'contributor', 'author', 'editor', 'administrator' ) as $role ) { 108 116 $wp_role = get_role( $role ); 109 117 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-i18n.php
r3438 r3511 7 7 * @package WordPressdotorg\Plugin_Directory 8 8 */ 9 class i18n {9 class I18n { 10 10 11 11 /** -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-markdown.php
r3180 r3511 15 15 class Markdown extends \Michelf\MarkdownExtra { 16 16 17 /** 18 * @param string $text 19 * @return string 20 */ 17 21 public function transform( $text ) { 18 22 $text = $this->code_trick( trim( $text ) ); 19 // Convert any `= Section =` headers into a real header 23 24 // Convert any `= Section =` headers into a real header. 20 25 $text = preg_replace( '/^[\s]*=[\s]+(.+?)[\s]+=/m', "\n" . '<h4>$1</h4>' . "\n", $text ); 21 26 … … 25 30 } 26 31 32 /** 33 * @access protected 34 * 35 * @param string $text 36 * @return string 37 */ 27 38 protected function code_trick( $text ) { 28 // when doing markdown, first take any user formatted code blocks and turn them into backticks so that 29 // markdown will preserve things like underscores in code blocks 39 40 /* 41 * When doing markdown, first take any user formatted code blocks and turn them into backticks so that 42 * markdown will preserve things like underscores in code blocks. 43 */ 30 44 $text = preg_replace_callback( "!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( $this, 'code_trick_decodeit_cb' ), $text ); 31 45 $text = str_replace( array( "\r\n", "\r" ), "\n", $text ); 32 46 33 // Markdown can do inline code, we convert bbPress style block level code to Markdown style 47 // Markdown can do inline code, we convert bbPress style block level code to Markdown style. 34 48 $text = preg_replace_callback( "!(^|\n)([ \t]*?)`(.*?)`!s", array( $this, 'code_trick_indent_cb' ), $text ); 35 49 … … 37 51 } 38 52 53 /** 54 * @access protected 55 * 56 * @param array $matches 57 * @return string 58 */ 39 59 protected function code_trick_indent_cb( $matches ) { 40 60 $text = $matches[3]; … … 44 64 } 45 65 66 /** 67 * @access protected 68 * 69 * @param array $matches 70 * @return string 71 */ 46 72 protected function code_trick_decodeit_cb( $matches ) { 47 $text = $matches[2];48 73 $trans_table = array_flip( get_html_translation_table( HTML_ENTITIES ) ); 49 $text = strtr( $text, $trans_table ); 50 $text = str_replace( '<br />', '', $text ); 51 $text = str_replace( '&', '&', $text ); 52 $text = str_replace( ''', "'", $text ); 74 75 $text = $matches[2]; 76 $text = strtr( $text, $trans_table ); 77 $text = str_replace( '<br />', '', $text ); 78 $text = str_replace( '&', '&', $text ); 79 $text = str_replace( ''', "'", $text ); 53 80 54 81 if ( '<pre><code>' == $matches[1] ) { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r3506 r3511 12 12 13 13 /** 14 * Local cache for translated content injected into meta 14 * Local cache for translated content injected into meta. 15 * 16 * @access private 17 * 18 * @var array 15 19 */ 16 20 private $i18n_meta = array(); … … 18 22 /** 19 23 * Fetch the instance of the Plugin_Directory class. 24 * 25 * @static 20 26 */ 21 27 public static function instance() { … … 25 31 } 26 32 33 /** 34 * Plugin_Directory constructor. 35 * 36 * @access private 37 */ 27 38 private function __construct() { 28 39 add_action( 'init', array( $this, 'init' ) ); … … 44 55 add_filter( 'oembed_providers', array( $this, 'oembed_whitelist' ) ); 45 56 46 // Shim in postmeta support for data which doesn't yet live in postmeta 57 // Shim in postmeta support for data which doesn't yet live in postmeta. 47 58 add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 ); 48 59 49 60 add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 ); 50 61 51 // Load the API routes 62 // Load the API routes. 52 63 add_action( 'rest_api_init', array( __NAMESPACE__ . '\API\Base', 'load_routes' ) ); 53 64 54 // Load all Admin-specific items. 55 // Cannot be included on `admin_init` to allow access to menu hooks 65 /* 66 * Load all Admin-specific items. 67 * Cannot be included on `admin_init` to allow access to menu hooks. 68 */ 56 69 if ( defined( 'WP_ADMIN' ) && WP_ADMIN ) { 57 70 Customizations::instance(); 58 71 59 add_action( 'wp_insert_post_data', array( __NAMESPACE__ . '\Admin\Status_Transitions', 'can_change_post_status' ), 10, 2 );72 add_action( 'wp_insert_post_data', array( __NAMESPACE__ . '\Admin\Status_Transitions', 'can_change_post_status' ), 10, 2 ); 60 73 add_action( 'transition_post_status', array( __NAMESPACE__ . '\Admin\Status_Transitions', 'instance' ) ); 61 74 } … … 74 87 75 88 register_post_type( 'plugin', array( 76 'labels' 89 'labels' => array( 77 90 'name' => __( 'Plugins', 'wporg-plugins' ), 78 91 'singular_name' => __( 'Plugin', 'wporg-plugins' ), … … 105 118 'delete_posts' => 'do_not_allow', 106 119 'create_posts' => 'do_not_allow', 107 ) 120 ), 108 121 ) ); 109 122 … … 148 161 'capabilities' => array( 149 162 'assign_terms' => 'plugin_set_category', 150 ) 163 ), 151 164 ) ); 152 165 … … 156 169 'rewrite' => false, 157 170 'labels' => array( 158 'name' 171 'name' => __( 'Built For', 'wporg-plugins' ), 159 172 ), 160 173 'public' => true, … … 164 177 'capabilities' => array( 165 178 'assign_terms' => 'plugin_set_category', 166 ) 179 ), 167 180 ) ); 168 181 … … 172 185 'rewrite' => false, 173 186 'labels' => array( 174 'name' 187 'name' => __( 'Business Model', 'wporg-plugins' ), 175 188 ), 176 189 'public' => true, … … 180 193 'capabilities' => array( 181 194 'assign_terms' => 'plugin_set_category', 182 ) 195 ), 183 196 ) ); 184 197 … … 220 233 // /browse/ should be the popular archive view. 221 234 add_rewrite_rule( '^browse$', 'index.php?browse=popular', 'top' ); 235 222 236 // Create an archive for a users favorites too. 223 237 add_rewrite_rule( '^browse/favorites/([^/]+)$', 'index.php?browse=favorites&favorites_user=$matches[1]', 'top' ); 224 238 225 // Handle the old plugin tabs URLs 239 // Handle the old plugin tabs URLs. 226 240 add_rewrite_rule( '^([^/]+)/(installation|faq|screenshots|changelog|stats|developers|other_notes)$', 'index.php?redirect_plugin_tab=$matches[1]/#$matches[2]', 'top' ); 227 241 … … 229 243 //Capabilities::add_roles(); 230 244 231 // When this plugin is used in the context of a Rosetta site, handle it gracefully 245 // When this plugin is used in the context of a Rosetta site, handle it gracefully. 232 246 if ( 'wordpress.org' != $_SERVER['HTTP_HOST'] && defined( 'WPORG_PLUGIN_DIRECTORY_BLOGID' ) ) { 233 247 add_filter( 'option_home', array( $this, 'rosetta_network_localize_url' ) ); … … 236 250 237 251 if ( 'en_US' != get_locale() ) { 238 add_filter( 'get_term', array( __NAMESPACE__ . '\ i18n', 'translate_term' ) );252 add_filter( 'get_term', array( __NAMESPACE__ . '\I18n', 'translate_term' ) ); 239 253 add_filter( 'the_content', array( $this, 'translate_post_content' ), 1, 2 ); 240 254 add_filter( 'the_title', array( $this, 'translate_post_title' ), 1, 2 ); … … 250 264 // When Jetpack syncs, we want to add filters to inject additional metadata for Jetpack, so it syncs for ElasticSearch indexing. 251 265 add_action( 'shutdown', array( $this, 'append_meta_for_jetpack' ), 8 ); 252 253 266 } 254 267 … … 263 276 } 264 277 278 /** 279 * Register the Widgets used plugin detail pages. 280 */ 265 281 public function register_widgets() { 266 register_widget( __NAMESPACE__ . '\Widgets\Donate' );267 register_widget( __NAMESPACE__ . '\Widgets\Meta' );282 register_widget( __NAMESPACE__ . '\Widgets\Donate' ); 283 register_widget( __NAMESPACE__ . '\Widgets\Meta' ); 268 284 register_widget( __NAMESPACE__ . '\Widgets\Ratings' ); 269 285 register_widget( __NAMESPACE__ . '\Widgets\Support' ); … … 391 407 } 392 408 if ( 'plugin_built_for' == $term->taxonomy ) { 409 393 410 // Term slug = Post Slug = /%postname%/ 394 411 return trailingslashit( home_url( $term->slug ) ); … … 429 446 } 430 447 431 switch ( $wp_query-> query_vars['browse']) {448 switch ( $wp_query->get( 'browse' ) ) { 432 449 case 'favorites': 433 450 $favorites_user = wp_get_current_user(); 434 if ( ! empty( $wp_query->query_vars['favorites_user'] ) ) {451 if ( ! empty( $wp_query->query_vars['favorites_user'] ) ) { 435 452 $favorites_user = $wp_query->query_vars['favorites_user']; 436 } elseif ( ! empty( $_GET['favorites_user'] ) ) {453 } elseif ( ! empty( $_GET['favorites_user'] ) ) { 437 454 $favorites_user = $_GET['favorites_user']; 438 455 } … … 450 467 $wp_query->query_vars['p'] = -1; 451 468 } 452 453 469 break; 454 470 455 471 case 'new': 456 $wp_query->query_vars['orderby'] 472 $wp_query->query_vars['orderby'] = 'post_modified'; 457 473 break; 458 474 } 459 475 460 if ( isset( $wp_query->query['browse'] ) ) { 461 if ( 'beta' != $wp_query->query['browse'] && 'featured' != $wp_query->query['browse'] ) { 462 unset( $wp_query->query_vars['browse'] ); 463 464 add_filter( 'the_posts', function( $posts, $wp_query ) { 465 // Fix the queried object for the archive view 466 if ( ! $wp_query->queried_object && isset( $wp_query->query['browse'] ) ) { 467 $wp_query->query_vars['browse'] = $wp_query->query['browse']; 468 $wp_query->queried_object = get_term_by( 'slug', $wp_query->query['browse'], 'plugin_section' ); 469 } 470 return $posts; 471 }, 10, 2 ); 472 473 } 476 if ( isset( $wp_query->query['browse'] ) && 'beta' != $wp_query->query['browse'] && 'featured' != $wp_query->query['browse'] ) { 477 unset( $wp_query->query_vars['browse'] ); 478 479 add_filter( 'the_posts', function( $posts, $wp_query ) { 480 481 // Fix the queried object for the archive view. 482 if ( ! $wp_query->queried_object && isset( $wp_query->query['browse'] ) ) { 483 $wp_query->query_vars['browse'] = $wp_query->query['browse']; 484 $wp_query->queried_object = get_term_by( 'slug', $wp_query->query['browse'], 'plugin_section' ); 485 } 486 487 return $posts; 488 }, 10, 2 ); 474 489 } 475 490 … … 485 500 * @param string $content Post content. 486 501 * @param string $section Optional. Which readme section to translate. 502 * @param int $post_id Optional. Post ID. Default: 0. 487 503 * @return string 488 504 */ 489 public function translate_post_content( $content, $section = null, $post_id = null) {505 public function translate_post_content( $content, $section = null, $post_id = 0 ) { 490 506 if ( is_null( $section ) ) { 491 507 return $content; … … 514 530 * Returns the requested page's excerpt, translated. 515 531 * 516 * @param string $excerpt517 * @param \WP_Post $post532 * @param string $excerpt 533 * @param int|\WP_Post $post 518 534 * @return string 519 535 */ … … 523 539 524 540 /** 525 * Shutdown action that will add a filter to inject additional postmeta containing translated content if Jetpack is syncing.526 * 541 * Shutdown action that will add a filter to inject additional postmeta containing translated content if Jetpack 542 * is syncing. 527 543 */ 528 544 public function append_meta_for_jetpack() { 529 // Guess if a Jetpack sync is scheduled to run. It runs during shutdown at a lower priority than this action, so we can get in first. 530 // Fetching the extra meta to inject is expensive, so we only want to do this if a sync is likely. 531 if ( class_exists( 'Jetpack' ) && !empty(\Jetpack::$instance->sync->sync) ) { 545 546 /* 547 * Guess if a Jetpack sync is scheduled to run. It runs during shutdown at a lower priority than this action, 548 * so we can get in first.Fetching the extra meta to inject is expensive, so we only want to do this if a sync 549 * is likely. 550 */ 551 if ( class_exists( 'Jetpack' ) && ! empty( \Jetpack::$instance->sync->sync ) ) { 532 552 add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ), 10, 2 ); 533 553 } 534 535 554 } 536 555 … … 538 557 * Filter for wporg_plugins_custom_meta_fields to inject translated content for ES. 539 558 * 559 * @global string $locale Current locale. 560 * 540 561 * @param array $meta 541 * @param int $post_id562 * @param int $post_id 542 563 * @return array 543 564 */ 544 565 public function filter_post_meta_i18n( $meta, $post_id ) { 545 // Prevent recursion and repeat runs 566 567 // Prevent recursion and repeat runs. 546 568 remove_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ) ); 547 569 548 570 if ( $post_id <= 200 ) { 549 $locales_to_sync = array( 'fr_FR', 'es_ES' ); // This should probably be a list of available translations for the plugin readme. 571 572 // This should probably be a list of available translations for the plugin readme. 573 $locales_to_sync = array( 574 'fr_FR', 575 'es_ES', 576 ); 550 577 551 578 global $locale; 552 579 $_locale = $locale; 580 553 581 foreach ( $locales_to_sync as $locale ) { 554 $this->i18n_meta[ $post_id]['title_'.$locale]= $this->translate_post_title( get_the_title( $post_id ), $post_id );555 $this->i18n_meta[ $post_id]['excerpt_'.$locale] = $this->translate_post_excerpt( get_the_excerpt( $post_id ), $post_id );556 557 // Split up the content to translate it in sections 558 $content = '';582 $this->i18n_meta[ $post_id ][ 'title_' . $locale ] = $this->translate_post_title( get_the_title( $post_id ), $post_id ); 583 $this->i18n_meta[ $post_id ][ 'excerpt_' . $locale ] = $this->translate_post_excerpt( get_the_excerpt( $post_id ), $post_id ); 584 585 // Split up the content to translate it in sections. 586 $content = ''; 559 587 $sections = $this->split_post_content_into_pages( get_the_content( $post_id ) ); 560 588 foreach ( $sections as $section => $section_content ) { 561 589 $content .= $this->translate_post_content( $section_content, $section, $post_id ); 562 590 } 563 $this->i18n_meta[$post_id]['content_'.$locale] = $content; 564 591 $this->i18n_meta[ $post_id ][ 'content_' . $locale ] = $content; 565 592 } 566 593 567 594 $locale = $_locale; 568 595 569 $meta = array_merge( $meta, array_keys( $this->i18n_meta[$post_id] ) ); 570 } 571 572 add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n'), 10, 2 ); 596 $meta = array_merge( $meta, array_keys( $this->i18n_meta[ $post_id ] ) ); 597 } 598 599 add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ), 10, 2 ); 600 573 601 return $meta; 574 602 } 575 576 603 577 604 /** … … 583 610 public function filter_allowed_post_types( $allowed_post_types ) { 584 611 $allowed_post_types[] = 'plugin'; 612 585 613 return $allowed_post_types; 586 614 } … … 588 616 /** 589 617 * Filters the available public query vars to add our custom parameters. 618 * 619 * @param array $vars Public query vars. 620 * @return array 590 621 */ 591 622 public function filter_query_vars( $vars ) { 592 623 $vars[] = 'favorites_user'; 593 624 $vars[] = 'redirect_plugin_tab'; 625 594 626 return $vars; 595 627 } … … 602 634 */ 603 635 public function filter_jetpack_options( $new_value ) { 604 if ( is_array( $new_value ) && array_key_exists( 'public', $new_value ) ) 636 if ( is_array( $new_value ) && array_key_exists( 'public', $new_value ) ) { 605 637 $new_value['public'] = 1; 638 } 606 639 607 640 return $new_value; … … 621 654 */ 622 655 function redirect_old_plugin_urls() { 623 // Handle a redirect for /$plugin/$tab_name/ to /$plugin/#$tab_name 656 657 // Handle a redirect for /$plugin/$tab_name/ to /$plugin/#$tab_name. 624 658 if ( get_query_var( 'redirect_plugin_tab' ) ) { 625 659 wp_safe_redirect( site_url( get_query_var( 'redirect_plugin_tab' ) ) ); … … 630 664 if ( is_404() ) { 631 665 632 // [1] => plugins [2] => example-plugin-name [2..] => random() 666 // [1] => plugins [2] => example-plugin-name [2..] => random(). 633 667 $path = explode( '/', $_SERVER['REQUEST_URI'] ); 634 668 … … 646 680 } 647 681 648 // The about page is now over at /developers/ 682 // The about page is now over at /developers/. 649 683 if ( 'about' === $path[2] ) { 650 wp_safe_redirect( home_url( '/developers/' . ( ( isset( $path[3] ) && 'add' == $path[3] ) ? 'add/' : '' ) ) );684 wp_safe_redirect( home_url( '/developers/' . ( ( isset( $path[3] ) && 'add' == $path[3] ) ? 'add/' : '' ) ) ); 651 685 die(); 652 686 } 653 687 654 // Otherwise, handle a plugin redirect 688 // Otherwise, handle a plugin redirect. 655 689 if ( $plugin = self::get_plugin_post( $path[2] ) ) { 656 690 $is_disabled = in_array( $plugin->post_status, array( 'disabled', 'closed' ), true ); 657 691 658 692 if ( $is_disabled && current_user_can( 'edit_post', $plugin ) ) { 659 wp_safe_redirect( add_query_arg( array( 'post' => $plugin->ID, 'action' => 'edit' ), admin_url( 'post.php' ) ) ); 693 wp_safe_redirect( add_query_arg( array( 694 'post' => $plugin->ID, 695 'action' => 'edit', 696 ), admin_url( 'post.php' ) ) ); 660 697 die(); 661 698 } else if ( ! $is_disabled ) { … … 672 709 } 673 710 674 // new-style Search links 711 // new-style Search links. 675 712 if ( get_query_var( 's' ) && isset( $_GET['s'] ) ) { 676 713 wp_safe_redirect( site_url( '/search/' . urlencode( get_query_var( 's' ) ) . '/' ) ); … … 706 743 } 707 744 } 745 708 746 return false; 709 747 } ); … … 722 760 switch ( $meta_key ) { 723 761 case 'downloads': 724 $post = get_post( $object_id );762 $post = get_post( $object_id ); 725 763 $count = Template::get_downloads_count( $post ); 726 727 return array( $count ); 764 $value = array( $count ); 728 765 break; 766 729 767 case 'rating': 730 768 $post = get_post( $object_id ); … … 733 771 break; 734 772 } 773 735 774 $rating = wporg_get_rating_avg( 'plugin', $post->post_name ); 736 737 return array( $rating ); 775 $value = array( $rating ); 738 776 break; 777 739 778 case 'ratings': 740 779 $post = get_post( $object_id ); … … 742 781 break; 743 782 } 783 744 784 $ratings = wporg_get_rating_counts( 'plugin', $post->post_name ); 745 746 return array( $ratings ); 785 $value = array( $ratings ); 747 786 break; 787 748 788 case false: 789 749 790 // In the event $meta_key is false, the caller wants all meta fields, so we'll append our custom ones here too. 750 791 remove_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ) ); … … 760 801 761 802 foreach ( $custom_meta_fields as $key ) { 762 // When WordPress calls `get_post_meta( $post_id, false )` it expects an array of maybe_serialize()'d data 803 804 // When WordPress calls `get_post_meta( $post_id, false )` it expects an array of maybe_serialize()'d data. 763 805 $shimed_data = $this->filter_shim_postmeta( false, $object_id, $key ); 764 806 if ( $shimed_data ) { … … 766 808 } 767 809 } 768 769 810 break; 811 770 812 default: 771 813 if ( isset( $this->i18n_meta[ $object_id ][ $meta_key ] ) ) { … … 774 816 break; 775 817 } 818 776 819 return $value; 777 820 } … … 823 866 * Retrieve the WP_Post object representing a given plugin. 824 867 * 825 * @param $plugin_slug string|\WP_Post The slug of the plugin to retrieve. 868 * @static 869 * @global \WP_Post $post WordPress post object. 870 * 871 * @param string|\WP_Post $plugin_slug The slug of the plugin to retrieve. 826 872 * @return \WP_Post|bool 827 873 */ 828 static public function get_plugin_post( $plugin_slug ) {874 public static function get_plugin_post( $plugin_slug ) { 829 875 global $post; 876 830 877 if ( $plugin_slug instanceof \WP_Post ) { 831 878 return $plugin_slug; 832 879 } 880 833 881 // Use the global $post object when it matches to avoid hitting the database. 834 if ( ! empty( $post ) && 'plugin' == $post->post_type && $plugin_slug == $post->post_name ) {882 if ( ! empty( $post ) && 'plugin' == $post->post_type && $plugin_slug == $post->post_name ) { 835 883 return $post; 836 884 } … … 841 889 // We have a $post. 842 890 } else { 891 843 892 // get_post_by_slug(); 844 893 $posts = get_posts( array( … … 847 896 'post_status' => array( 'publish', 'pending', 'disabled', 'closed', 'draft', 'approved' ), 848 897 ) ); 898 849 899 if ( ! $posts ) { 850 900 $post = false; … … 861 911 /** 862 912 * Create a new post entry for a given plugin slug. 913 * 914 * @static 863 915 * 864 916 * @param array $args { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php
r3468 r3511 14 14 public $i18n_cache_group = 'plugins-i18n'; 15 15 16 /** 17 * @var string 18 */ 16 19 public $master_project; 17 20 21 /** 22 * @static 23 * 24 * @var bool 25 */ 18 26 public static $use_cache = true; 27 28 /** 29 * @static 30 * 31 * @var bool 32 */ 19 33 public static $set_cache = true; 20 34 21 35 /** 36 * @access protected 37 * 22 38 * @var \wpdb WordPress database abstraction object. 23 39 */ … … 26 42 /** 27 43 * Fetch the instance of the Plugin_I18n class. 44 * 45 * @static 28 46 */ 29 47 public static function instance() { … … 31 49 32 50 global $wpdb; 51 33 52 return ! is_null( $instance ) ? $instance : $instance = new Plugin_I18n( $wpdb ); 34 53 } 35 54 36 function __construct( $db, $tracker = null ) { 37 if ( !empty( $db ) && is_object( $db ) ) { 55 /** 56 * Plugin_I18n constructor. 57 * 58 * @access private 59 * 60 * @param \wpdb $db WordPress database abstraction object. 61 * @param null $tracker 62 */ 63 private function __construct( $db, $tracker = null ) { 64 if ( ! empty( $db ) && is_object( $db ) ) { 38 65 $this->db = $db; 39 66 } … … 43 70 44 71 /** 45 * Generates and returns a standard cache key format, for consistency 46 * 47 * @param string $slug Plugin slug 48 * @param string $branch dev|stable 49 * @param string $suffix Arbitrary cache key suffix, if needed for uniqueness 50 * 72 * Generates and returns a standard cache key format, for consistency. 73 * 74 * @param string $slug Plugin slug 75 * @param string $branch dev|stable 76 * @param string $suffix Optional. Arbitrary cache key suffix, if needed for uniqueness. 51 77 * @return string Cache key 52 78 */ 53 function cache_key( $slug, $branch, $suffix = null ) { 54 // EG keys 55 // plugin:press-this:stable-readme:originals 56 // plugin:press-this:stable-readme:original:title 57 // plugin:press-this:stable-readme:fr:title 79 public function cache_key( $slug, $branch, $suffix = '' ) { 80 81 /* 82 * EG keys 83 * plugin:press-this:stable-readme:originals 84 * plugin:press-this:stable-readme:original:title 85 * plugin:press-this:stable-readme:fr:title 86 */ 58 87 $key = "{$this->master_project}:{$slug}:{$branch}"; 59 if ( ! empty( $suffix ) ) {88 if ( ! empty( $suffix ) ) { 60 89 $key .= ":{$suffix}"; 61 90 } 91 62 92 return $key; 63 93 } 64 94 65 95 /** 66 * Cache getting, with proper global cache group 67 * 68 * @param string $slug Plugin slug 69 * @param string $branch dev|stable 70 * @param string $suffix Arbitrary cache key suffix, if needed for uniqueness 71 * 96 * Cache getting, with proper global cache group. 97 * 98 * @param string $slug Plugin slug 99 * @param string $branch dev|stable 100 * @param string $suffix Optional. Arbitrary cache key suffix, if needed for uniqueness. 72 101 * @return bool|mixed As returned by wp_cache_set() 73 102 */ 74 function cache_get( $slug, $branch, $suffix = null) {103 public function cache_get( $slug, $branch, $suffix = '' ) { 75 104 if ( ! self::$use_cache ) { 76 105 return false; … … 78 107 79 108 $key = $this->cache_key( $slug, $branch, $suffix ); 109 80 110 return wp_cache_get( $key, $this->i18n_cache_group ); 81 111 } … … 88 118 * @param mixed $content Content to be cached. 89 119 * @param string $suffix Optional. Arbitrary cache key suffix, if needed for uniqueness. 90 *91 120 * @return bool As returned by wp_cache_set() 92 121 */ 93 function cache_set( $slug, $branch, $content, $suffix = null) {122 public function cache_set( $slug, $branch, $content, $suffix = '' ) { 94 123 if ( ! self::$set_cache ) { 95 124 return false; … … 97 126 98 127 $key = $this->cache_key( $slug, $branch, $suffix ); 128 99 129 return wp_cache_set( $key, $content, $this->i18n_cache_group ); 100 130 } 101 131 102 132 /** 103 * Gets a GlotPress branch ID 104 * 105 * @param string $slug Plugin slug133 * Gets a GlotPress branch ID. 134 * 135 * @param string $slug Plugin slug 106 136 * @param string $branch dev|stable 107 137 * 108 138 * @return bool|int|mixed 109 139 */ 110 function get_gp_branch_id( $slug, $branch ) {140 public function get_gp_branch_id( $slug, $branch ) { 111 141 $cache_suffix = "branch_id"; 112 142 … … 130 160 131 161 /** 132 * Gets GlotPress "originals" based on passed parameters 133 * 134 * @param string $slug Plugin slug 135 * @param string $branch dev|stable 136 * @param string $key Unique key 137 * @param string $str String to match in GP 138 * 162 * Gets GlotPress "originals" based on passed parameters. 163 * 164 * @param string $slug Plugin slug 165 * @param string $branch dev|stable 166 * @param string $key Unique key 167 * @param string $str String to match in GP 139 168 * @return array|bool|mixed|null 140 169 */ 141 function get_gp_originals( $slug, $branch, $key, $str ) { 170 public function get_gp_originals( $slug, $branch, $key, $str ) { 171 142 172 // Try to get a single original with the whole content first (title, etc), if passed, or get them all otherwise. 143 if ( ! empty( $key ) && !empty( $str ) ) {173 if ( ! empty( $key ) && ! empty( $str ) ) { 144 174 $originals = $this->search_gp_original( $slug, $branch, $key, $str ); 145 if ( !empty( $originals ) ) { 175 176 // Do not cache this as originals, search_gp_original() does its own caching. 177 if ( ! empty( $originals ) ) { 146 178 return array( $originals ); 147 179 } 148 // Do not cache this as originals, search_gp_original() does its own caching149 180 } 150 181 … … 167 198 168 199 if ( empty( $originals ) ) { 169 $originals = array(); // still cache if empty, but as array, never false 200 201 // Still cache if empty, but as array, never false. 202 $originals = array(); 170 203 } 171 204 … … 176 209 177 210 /** 178 * Get GlotPress translation set ID based on passed params 179 * 180 * @param string $slug Plugin slug211 * Get GlotPress translation set ID based on passed params. 212 * 213 * @param string $slug Plugin slug 181 214 * @param string $branch dev|stable 182 215 * @param string $locale EG: fr 183 *184 216 * @return bool|int|mixed 185 217 */ 186 function get_gp_translation_set_id( $slug, $branch, $locale ) {218 public function get_gp_translation_set_id( $slug, $branch, $locale ) { 187 219 $cache_suffix = "{$locale}:translation_set_id"; 188 220 … … 202 234 203 235 if ( empty( $translation_set_id ) ) { 236 204 237 // Don't give up yet. Might be given fr_FR, which actually exists as locale=fr in GP. 205 238 $translation_set_id = $this->db->get_var( $this->db->prepare( 206 239 'SELECT id FROM ' . GLOTPRESS_TABLE_PREFIX . 'translation_sets WHERE project_id = %d AND locale = %s', 207 $branch_id, preg_replace( '/^([^-]+)(-.+)?$/', '\1', $locale ) ) ); 240 $branch_id, preg_replace( '/^([^-]+)(-.+)?$/', '\1', $locale ) 241 ) ); 208 242 } 209 243 … … 218 252 219 253 /** 220 * Searches GlotPress "originals" for the passed string 221 * 222 * @param string $slug Plugin slug 223 * @param string $branch dev|stable 224 * @param string $key Unique key 225 * @param string $str String to be searched for 226 * 254 * Searches GlotPress "originals" for the passed string. 255 * 256 * @param string $slug Plugin slug 257 * @param string $branch dev|stable 258 * @param string $key Unique key 259 * @param string $str String to be searched for 227 260 * @return bool|mixed|null 228 261 */ 229 function search_gp_original( $slug, $branch, $key, $str ) {262 public function search_gp_original( $slug, $branch, $key, $str ) { 230 263 $cache_suffix = "original:{$key}"; 231 264 … … 255 288 256 289 /** 257 * Somewhat emulated equivalent of __() for content translation drawn directly from the GlotPress DB 258 * 259 * @param string $key Unique key, used for caching290 * Somewhat emulated equivalent of __() for content translation drawn directly from the GlotPress DB. 291 * 292 * @param string $key Unique key, used for caching 260 293 * @param string $content Content to be translated 261 * @param array $args Misc arguments, such as BBPress topic id (otherwise acquired from global $topic_id)262 * 263 * @return mixed264 */ 265 function translate( $key, $content, $args = array() ) {294 * @param array $args Optional. Misc arguments, such as BBPress topic id 295 * (otherwise acquired from global $topic_id). 296 * @return string 297 */ 298 public function translate( $key, $content, $args = array() ) { 266 299 if ( empty( $key ) || empty( $content ) ) { 267 300 return $content; … … 285 318 } 286 319 287 $server_name 320 $server_name = strtolower( $_SERVER['SERVER_NAME'] ); 288 321 if ( 'api.wordpress.org' == $server_name ) { 289 // Support formats like fr, haz, and en_GB 322 323 // Support formats like fr, haz, and en_GB. 290 324 if ( ! empty( $_REQUEST['locale'] ) ) { 291 325 $wp_locale = preg_replace( '/[^a-zA-Z_]/', '', $_REQUEST['locale'] ); … … 309 343 } 310 344 311 $locale = $gp_locale->slug; // The slug is the locale of a translation set. 312 $slug = $post->post_name; 345 // The slug is the locale of a translation set. 346 $locale = $gp_locale->slug; 347 $slug = $post->post_name; 313 348 314 349 $post->stable_tag = get_post_meta( $post->ID, 'stable_tag', true ); … … 326 361 $cache_suffix = "{$locale}:{$key}"; 327 362 328 // Try the cache 363 // Try the cache. 329 364 if ( false !== ( $cache = $this->cache_get( $slug, $branch, $cache_suffix ) ) ) { 330 365 // DEBUG … … 368 403 369 404 /** 370 * Takes content, searches for $original, and replaces it by $translation 371 * 372 * @param string $original English string 373 * @param string $translation Translation 374 * @param string $content Content to be searched 375 * 405 * Takes content, searches for $original, and replaces it by $translation. 406 * 407 * @param string $original English string. 408 * @param string $translation Translation. 409 * @param string $content Content to be searched. 376 410 * @return mixed 377 411 */ 378 function translate_gp_original( $original, $translation, $content ) {412 public function translate_gp_original( $original, $translation, $content ) { 379 413 if ( false === strpos( $content, '<' ) ) { 380 414 $content = str_replace( $original, $translation, $content ); 381 415 } else { 382 416 $original = preg_quote( $original, '/' ); 383 $content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", "\\1{$translation}\\3", $content );417 $content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", "\\1{$translation}\\3", $content ); 384 418 } 385 419 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r3495 r3511 12 12 * Returns a string representing the number of active installs for an item. 13 13 * 14 * @param bool $full Whether to include "active installs" suffix. Default: true. 14 * @static 15 * 16 * @param bool $full Optional. Whether to include "active installs" suffix. Default: true. 15 17 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 16 18 * @return string "1+ million" or "1+ million active installs" depending on $full. 17 19 */ 18 static function active_installs( $full = true, $post = null ) { 19 $post = get_post( $post ); 20 20 public static function active_installs( $full = true, $post = null ) { 21 $post = get_post( $post ); 21 22 $count = get_post_meta( $post->ID, 'active_installs', true ); 22 23 … … 28 29 $text = number_format_i18n( $count ) . '+'; 29 30 } 31 30 32 return $full ? sprintf( __( '%s active installs', 'wporg-plugins' ), $text ) : $text; 31 33 } 32 34 33 34 /** 35 * @param \WP_Post|int $post Optional. 35 /** 36 * Returns the number of downloads for a plugin. 37 * 38 * @static 39 * @global \wpdb $wpdb WordPress database abstraction object. 40 * 41 * @param int|\WP_Post|null $post Optional. 36 42 * @return int 37 43 */ 38 static function get_downloads_count( $post = null ) {44 public static function get_downloads_count( $post = null ) { 39 45 $post = get_post( $post ); 40 46 … … 52 58 53 59 /** 60 * Returns the cumulative number of downloads of all plugins. 61 * 62 * @static 63 * @global \wpdb $wpdb WordPress database abstraction object. 64 * 54 65 * @return int 55 66 */ 56 static function get_total_downloads() {67 public static function get_total_downloads() { 57 68 if ( false === ( $count = wp_cache_get( 'plugin_download_count', 'plugin_download_count' ) ) ) { 58 69 global $wpdb; … … 67 78 /** 68 79 * Displays a plugin's rating with the amount of ratings it has received. 80 * 81 * @static 69 82 * 70 83 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. … … 87 100 88 101 /** 102 * Returns the available sections for a plugin. 103 * 104 * @static 105 * 89 106 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 90 107 * @return array 91 108 */ 92 static function get_plugin_sections( $post = null ) {109 public static function get_plugin_sections( $post = null ) { 93 110 $plugin = get_post( $post ); 94 111 $plugin_slug = $plugin->post_name; … … 109 126 $raw_sections = array_unique( array_merge( $raw_sections, $default_sections ) ); 110 127 111 $sections 112 $title = $url = '';113 $permalink 128 $sections = array(); 129 $title = $url = ''; 130 $permalink = get_permalink(); 114 131 115 132 foreach ( $raw_sections as $section_slug ) { … … 183 200 * Retrieve the Plugin Icon details for a plugin. 184 201 * 202 * @static 203 * 185 204 * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug. 186 * @param string $output O utput type. 'html' or 'raw'. Default: 'raw'.205 * @param string $output Optional. Output type. 'html' or 'raw'. Default: 'raw'. 187 206 * @return mixed 188 207 */ 189 static function get_plugin_icon( $plugin, $output = 'raw' ) {208 public static function get_plugin_icon( $plugin, $output = 'raw' ) { 190 209 $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin ); 191 210 if ( ! $plugin ) { … … 209 228 /* false = the resolution of the icon, this is NOT disabled */ 210 229 case false && 'icon.svg' == $file: 211 $svg 230 $svg = self::get_asset_url( $plugin_slug, $info ); 212 231 break; 213 232 } … … 226 245 // Use the average color of the first known banner as the icon background color 227 246 if ( $color = get_post_meta( $plugin->ID, 'assets_banners_color', true ) ) { 228 if ( strlen( $color ) == 6 && strspn( $color, 'abcdef0123456789' )== 6 ) {247 if ( strlen( $color ) === 6 && strspn( $color, 'abcdef0123456789' ) === 6 ) { 229 248 $icon->setColor( '#' . $color ); 230 249 } … … 236 255 switch ( $output ) { 237 256 case 'html': 238 $id = "plugin-icon-{$plugin_slug}";239 $html = "<style type='text/css'>";257 $id = "plugin-icon-{$plugin_slug}"; 258 $html = "<style type='text/css'>"; 240 259 $html .= "#{$id} { background-image: url('{$icon}'); } .plugin-icon { background-size: 128px 128px; height: 128px; width: 128px; }"; 241 260 if ( ! empty( $icon_2x ) && ! $generated ) { … … 257 276 * Retrieve the Plugin Icon details for a plugin. 258 277 * 278 * @static 279 * 259 280 * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug. 260 * @param string $output O utput type. 'html' or 'raw'. Default: 'raw'.281 * @param string $output Optional. Output type. 'html' or 'raw'. Default: 'raw'. 261 282 * @return mixed 262 283 */ 263 static function get_plugin_banner( $plugin, $output = 'raw' ) {284 public static function get_plugin_banner( $plugin, $output = 'raw' ) { 264 285 $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin ); 265 286 if ( ! $plugin ) { … … 267 288 } 268 289 269 $banner = $banner_2x = false;290 $banner = $banner_2x = false; 270 291 $plugin_slug = $plugin->post_name; 271 292 $raw_banners = get_post_meta( $plugin->ID, 'assets_banners', true ); 272 293 273 294 // Split in rtl and non-rtl banners. 274 $rtl_banners = array_filter( $raw_banners, function ( $info ) {295 $rtl_banners = array_filter( $raw_banners, function ( $info ) { 275 296 return (bool) stristr( $info['filename'], '-rtl' ); 276 297 } ); … … 310 331 switch ( $output ) { 311 332 case 'html': 312 $id = "plugin-banner-{$plugin_slug}";313 $html = "<style type='text/css'>";333 $id = "plugin-banner-{$plugin_slug}"; 334 $html = "<style type='text/css'>"; 314 335 $html .= "#{$id} { background-image: url('{$banner}'); }"; 315 336 if ( ! empty( $banner_2x ) ) { … … 329 350 330 351 /** 331 * @param $plugin 332 * @param $asset 352 * Generates and returns the URL to a passed asset. 353 * 354 * Assets can be screenshots, icons, banners, etc. 355 * 356 * @static 357 * 358 * @param string $plugin Plugin slug. 359 * @param array $asset Assets folder information. 333 360 * @return string 334 361 */ 335 static function get_asset_url( $plugin, $asset ) {362 public static function get_asset_url( $plugin, $asset ) { 336 363 if ( ! empty( $asset['location'] ) && 'plugin' == $asset['location'] ) { 337 // Screenshots in the plugin folder - /plugins/plugin-name/screenshot-1.png 364 365 // Screenshots in the plugin folder - /plugins/plugin-name/screenshot-1.png. 338 366 $format = 'https://s.w.org/plugins/%s/%s?rev=%s'; 339 367 } else { 340 // Images in the assets folder - /plugin-name/assets/screenshot-1.png 368 369 // Images in the assets folder - /plugin-name/assets/screenshot-1.png. 341 370 $format = 'https://ps.w.org/%s/assets/%s?rev=%s'; 342 371 } … … 353 382 * A helper method to create dashicon stars. 354 383 * 355 * @type int|array { 384 * @static 385 * 386 * @param int|array $args { 356 387 * If numeric arg passed, assumed to be 'rating'. 357 388 * … … 362 393 * @return string The Rating HTML. 363 394 */ 364 static function dashicons_stars( $args = array() ) { 365 $defaults = array( 366 'rating' => 0, 367 'template' => '<span class="%1$s"></span>' 368 ); 369 $r = wp_parse_args( ( is_numeric( $args ) ? array( 'rating' => $args ) : $args ), $defaults ); 370 371 $rating = round( $r['rating'] / 0.5 ) * 0.5; 372 $template = $r['template']; 395 public static function dashicons_stars( $args = array() ) { 396 $args = wp_parse_args( ( is_numeric( $args ) ? array( 'rating' => $args ) : $args ), array( 397 'rating' => 0, 398 'template' => '<span class="%1$s"></span>', 399 ) ); 400 401 $rating = round( $args['rating'] / 0.5 ) * 0.5; 402 $template = $args['template']; 373 403 $title_template = __( '%s out of 5 stars', 'wporg-plugins' ); 374 $title = sprintf( $title_template, $rating );375 376 $output = '<div class="wporg-ratings" title="' . esc_attr( $title ) . '" data-title-template="' . esc_attr( $title_template ) . '" data-rating="' . esc_attr( $rating ) . '" style="color:#ffb900;">';404 $title = sprintf( $title_template, $rating ); 405 406 $output = '<div class="wporg-ratings" title="' . esc_attr( $title ) . '" data-title-template="' . esc_attr( $title_template ) . '" data-rating="' . esc_attr( $rating ) . '" style="color:#ffb900;">'; 377 407 $counter = round( $rating * 2 ); 378 for ( $i = 1; $i <= 5; $i++ ) { 379 switch ($counter) { 380 case 0: 381 $output .= sprintf( $template, 'dashicons dashicons-star-empty', $i ); 382 break; 383 case 1: 384 $output .= sprintf( $template, 'dashicons dashicons-star-half', $i ); 385 $counter--; 386 break; 387 default: 388 $output .= sprintf( $template, 'dashicons dashicons-star-filled', $i ); 389 $counter -= 2; 390 break; 408 for ( $i = 1; $i <= 5; $i++ ) { 409 switch ( $counter ) { 410 case 0: 411 $output .= sprintf( $template, 'dashicons dashicons-star-empty', $i ); 412 break; 413 414 case 1: 415 $output .= sprintf( $template, 'dashicons dashicons-star-half', $i ); 416 $counter--; 417 break; 418 419 default: 420 $output .= sprintf( $template, 'dashicons dashicons-star-filled', $i ); 421 $counter -= 2; 422 break; 391 423 } 392 424 } 393 425 $output .= '</div>'; 426 394 427 return $output; 395 428 } 396 429 397 430 /** 398 * Generate a Download link for a given plugin & version.431 * Generate a download link for a given plugin & version. 399 432 * 400 433 * @param \WP_Post $post The Plugin Post. … … 419 452 * Properly encodes a string to UTF-8. 420 453 * 454 * @static 455 * 421 456 * @param string $string 422 457 * @return string -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php
r3510 r3511 12 12 /** 13 13 * Retrieve the average color of a specified image. 14 * 14 15 * This currently relies upon the Jetpack libraries. 15 16 * 16 * @param $file_location string URL or filepath of image 17 * @return string|bool Average color as a hex value, False on failure 18 */ 19 static function get_image_average_color( $file_location ) { 17 * @static 18 * 19 * @param $file_location string URL or filepath of image. 20 * @return string|bool Average color as a hex value, False on failure. 21 */ 22 public static function get_image_average_color( $file_location ) { 20 23 if ( ! class_exists( 'Tonesque' ) && function_exists( 'jetpack_require_lib' ) ) { 21 24 jetpack_require_lib( 'tonesque' ); 22 25 } 26 23 27 if ( ! class_exists( 'Tonesque' ) ) { 24 28 return false; … … 33 37 * Returns the two latest reviews of a specific plugin. 34 38 * 39 * @static 35 40 * @global \wpdb $wpdb WordPress database abstraction object. 36 41 * … … 54 59 posts.post_position = 1 55 60 ORDER BY ratings.review_id DESC LIMIT 2", $plugin_slug ) ); 61 56 62 wp_cache_set( "{$plugin_slug}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS ); 57 63 } … … 62 68 /** 63 69 * Retrieve a list of users who have commit to a specific plugin. 70 * 71 * @static 72 * @global \wpdb $wpdb WordPress database abstraction object. 64 73 * 65 74 * @param string $plugin_slug The plugin slug. … … 67 76 */ 68 77 public static function get_plugin_committers( $plugin_slug ) { 69 global $wpdb;70 71 78 if ( false === ( $committers = wp_cache_get( "{$plugin_slug}_committer", 'wporg-plugins' ) ) ) { 79 global $wpdb; 80 72 81 $committers = $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) ); 73 82 … … 80 89 /** 81 90 * Retrieve a list of plugins a specific user has commit to. 91 * 92 * @static 93 * @global \wpdb $wpdb WordPress database abstraction object. 82 94 * 83 95 * @param int|\WP_User $user The user. … … 85 97 */ 86 98 public static function get_users_write_access_plugins( $user ) { 87 global $wpdb;88 99 if ( ! $user instanceof \WP_User ) { 89 100 $user = new \WP_User( $user ); 90 101 } 102 91 103 if ( ! $user->exists() ) { 92 104 return false; … … 94 106 95 107 if ( false === ( $plugins = wp_cache_get( "{$user->user_login}_committer", 'wporg-plugins' ) ) ) { 108 global $wpdb; 109 96 110 $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) ); 97 $plugins = array_map( function( $plugin ) { return trim( $plugin, '/' ); }, $plugins ); 111 $plugins = array_map( function ( $plugin ) { 112 return trim( $plugin, '/' ); 113 }, $plugins ); 98 114 99 115 wp_cache_set( "{$user->user_login}_committer", $plugins, 'wporg-plugins' ); … … 101 117 102 118 return $plugins; 103 104 119 } 105 120 106 121 /** 107 122 * Grant a user RW access to a plugin. 123 * 124 * @static 125 * @global \wpdb $wpdb WordPress database abstraction object. 108 126 * 109 127 * @param string $plugin_slug The plugin slug. … … 124 142 $existing_committers = self::get_plugin_committers( $plugin_slug ); 125 143 if ( in_array( $user->user_login, $existing_committers, true ) ) { 144 126 145 // User already has write access. 127 146 return true; … … 131 150 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 132 151 133 return (bool) $wpdb->insert( 134 PLUGINS_TABLE_PREFIX . 'svn_access', 135 array( 136 'path' => "/{$plugin_slug}", 137 'user' => $user->user_login, 138 'access' => 'rw', 139 ) 140 ); 152 return (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array( 153 'path' => "/{$plugin_slug}", 154 'user' => $user->user_login, 155 'access' => 'rw', 156 ) ); 141 157 } 142 158 143 159 /** 144 160 * Revoke a users RW access to a plugin. 161 * 162 * @static 163 * @global \wpdb $wpdb WordPress database abstraction object. 145 164 * 146 165 * @param string $plugin_slug The plugin slug. … … 162 181 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 163 182 164 return $wpdb->delete( 165 PLUGINS_TABLE_PREFIX . 'svn_access', 166 array( 167 'path' => "/{$plugin_slug}", 168 'user' => $user->user_login, 169 ) 170 ); 183 return $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array( 184 'path' => "/{$plugin_slug}", 185 'user' => $user->user_login, 186 ) ); 171 187 } 172 188 … … 177 193 * emails and cannot unsubscribe. 178 194 * 195 * @static 196 * 179 197 * @param string $plugin_slug The plugin to subscribe to. 180 * @param int|WP_User $user The user to subscribe. Default current user.181 * @param bool $subscribe Whether to subscribe (true) or unsubscribe (false).182 * 198 * @param int|WP_User $user Optional. The user to subscribe. Default current user. 199 * @param bool $subscribe Optional. Whether to subscribe (true) or unsubscribe (false). 200 * Default: true. 183 201 * @return bool Whether the user is subscribed. 184 202 */ … … 216 234 * function does not respect that status. 217 235 * 236 * @static 237 * 218 238 * @param string $plugin_slug The plugin to subscribe to. 219 * @param int|WP_User $user The user to check. Default current user. 220 * 239 * @param int|WP_User $user Optional. The user to check. Default current user. 221 240 * @return bool Whether the specified user is subscribed to commits. 222 241 */
Note: See TracChangeset
for help on using the changeset viewer.