Making WordPress.org

Changeset 4290


Ignore:
Timestamp:
10/23/2016 06:39:39 PM (10 years ago)
Author:
jmdodd
Message:

Support Forums: Add plugin contributor view.

Adds rewrite rules, feed, and custom view handlers.

See #2071.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php

    r4289 r4290  
    5353
    5454                                // If this is a feed, add filters to handle the custom view.
    55                                 if ( isset( $query_vars['feed'] ) && isset( $query_vars['bbp_view'] ) && in_array( $query_vars['bbp_view'], array( 'plugin-committer' ) ) ) {
     55                                if ( isset( $query_vars['feed'] ) && isset( $query_vars['bbp_view'] ) && in_array( $query_vars['bbp_view'], array( 'plugin-committer', 'plugin-contributor' ) ) ) {
    5656                                        $this->query = $query_vars;
    5757                                        add_filter( 'bbp_get_view_query_args', array( $this, 'get_view_query_args_for_feed' ), 10, 2 );
     
    8383                                                'field'       => 'slug',
    8484                                                'terms'       => self::get_plugin_slugs_by_committer( $this->user->user_login ),
     85                                        ) ),
     86                                        'show_stickies'   => false,
     87                                );
     88                                break;
     89                        case 'plugin-contributor' :
     90                                return array(
     91                                        'post_parent__in' => array( Plugin::PLUGINS_FORUM_ID, Plugin::REVIEWS_FORUM_ID ),
     92                                        'post_status'     => 'publish',
     93                                        'tax_query'       => array( array(
     94                                                'taxonomy'    => 'topic-plugin',
     95                                                'field'       => 'slug',
     96                                                'terms'       => $this->get_plugin_slugs_by_contributor( $this->user ),
    8597                                        ) ),
    8698                                        'show_stickies'   => false,
     
    125137                        // Add output filters and actions.
    126138                        add_filter( 'bbp_get_view_link', array( $this, 'get_view_link' ), 10, 2 );
     139
     140                } elseif ( $view == 'plugin-contributor' ) {
     141
     142                        $slugs = self::get_plugin_slugs_by_contributor( $this->user );
     143
     144                        // Add plugin-contributor view.
     145                        bbp_register_view(
     146                                'plugin-contributor',
     147                                sprintf( __( 'Plugin Contributor » %s', 'wporg-forums' ), esc_html( $this->user->user_login ) ),
     148                                array(
     149                                        'post_parent__in' => array( Plugin::PLUGINS_FORUM_ID, Plugin::REVIEWS_FORUM_ID ),
     150                                        'post_status'     => 'publish',
     151                                        'tax_query'       => array( array(
     152                                                'taxonomy'    => 'topic-plugin',
     153                                                'field'       => 'slug',
     154                                                'terms'       => $slugs,
     155                                        ) ),
     156                                        'show_stickies'   => false,
     157                                )
     158                        );
     159
     160                        // Add output filters and actions.
     161                        add_filter( 'bbp_get_view_link', array( $this, 'get_view_link' ), 10, 2 );
    127162                }
    128163        }
     
    136171                $priority   = 'top';
    137172
    138                 $plugin_committer_rule = bbp_get_view_slug() . '/plugin-committer/([^/]+)/';
     173                $plugin_committer_rule   = bbp_get_view_slug() . '/plugin-committer/([^/]+)/';
     174                $plugin_contributor_rule = bbp_get_view_slug() . '/plugin-contributor/([^/]+)/';
    139175
    140176                $feed_id    = 'feed';
     
    153189                add_rewrite_rule( $plugin_committer_rule . $paged_rule, 'index.php?' . $view_id . '=plugin-committer&wporg_user_login=$matches[1]&' . $paged_id . '=$matches[2]', $priority );
    154190                add_rewrite_rule( $plugin_committer_rule . $feed_rule,  'index.php?' . $view_id . '=plugin-committer&wporg_user_login=$matches[1]&' . $feed_id  . '=$matches[2]', $priority );
     191
     192                // Add plugin contributor rewrite rules.
     193                add_rewrite_rule( $plugin_contributor_rule . $base_rule,  'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]',                               $priority );
     194                add_rewrite_rule( $plugin_contributor_rule . $paged_rule, 'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]&' . $paged_id . '=$matches[2]', $priority );
     195                add_rewrite_rule( $plugin_contributor_rule . $feed_rule,  'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]&' . $feed_id  . '=$matches[2]', $priority );
    155196        }
    156197
     
    162203
    163204                $view = bbp_get_view_id( $view );
    164                 if ( ! in_array( $view, array( 'plugin-committer' ) ) ) {
     205                if ( ! in_array( $view, array( 'plugin-committer', 'plugin-contributor' ) ) ) {
    165206                        return $url;
    166207                }
     
    291332        }
    292333
     334        public static function get_plugin_slugs_by_contributor( $user ) {
     335                global $wpdb;
     336                $slugs = (array) $wpdb->get_col( $wpdb->prepare( "SELECT `topic_slug` FROM `" . PLUGINS_TABLE_PREFIX . "topics` WHERE `topic_poster` = %d AND topic_open = 1 AND topic_status = 0", $user->ID ) );
     337                $slugs = self::clean_slugs( $slugs );
     338                if ( $contributor = $wpdb->get_col( $wpdb->prepare( "SELECT `object_id` FROM `" . PLUGINS_TABLE_PREFIX . "meta` WHERE `object_type` = 'bb_topic' AND `meta_key` = 'contributors' AND `meta_value` LIKE %s", '%"' . str_replace( array( '%', '_' ), array( '\\%', '\\_' ), $user->user_login ) . '"%' ) ) ) {
     339                        if ( $contributor_slugs = $wpdb->get_col( "SELECT `topic_slug` FROM `" . PLUGINS_TABLE_PREFIX . "topics` WHERE `topic_id` IN (" . join( ',', $contributor ) . ") AND topic_open = 1 AND topic_status = 0" ) ) {
     340                                $slugs = array_unique( array_merge( $slugs, $contributor_slugs ) );
     341                        }
     342                }
     343                return $slugs;
     344        }
     345
    293346        public static function clean_slugs( $slugs ) {
    294347                $cleanslugs = array();
Note: See TracChangeset for help on using the changeset viewer.