| | 38 | } |
| | 39 | |
| | 40 | public function request( $query_vars ) { |
| | 41 | if ( isset( $query_vars['feed'] ) && isset( $query_vars['wporg_user_login'] ) ) { |
| | 42 | if ( isset( $query_vars['bbp_view'] ) && in_array( $query_vars['bbp_view'], array( 'plugin-committer' ) ) ) { |
| | 43 | $this->query = $query_vars; |
| | 44 | add_filter( 'bbp_get_view_query_args', array( $this, 'get_view_query_args_for_feed' ), 10, 2 ); |
| | 45 | |
| | 46 | // Override bbPress topic pubDate handling to show topic time and not last active time |
| | 47 | add_filter( 'get_post_metadata', array( $this, 'topic_pubdate_correction_for_feed' ), 10, 4 ); |
| | 48 | } |
| | 49 | } |
| | 50 | return $query_vars; |
| | 51 | } |
| | 52 | |
| | 53 | public function topic_pubdate_correction_for_feed( $value, $object_id, $meta_key, $single ) { |
| | 54 | // We only care about _bbp_last_active_time in this particular context |
| | 55 | if( $meta_key == '_bbp_last_active_time' ) { |
| | 56 | $value = get_post_time( 'Y-m-d H:i:s', true, $object_id ); |
| | 57 | } |
| | 58 | return $value; |
| | 59 | } |
| | 60 | |
| | 61 | public function get_view_query_args_for_feed( $retval, $view ) { |
| | 62 | switch( $this->query['bbp_view'] ) { |
| | 63 | case 'plugin-committer' : |
| | 64 | return array( |
| | 65 | 'post_parent__in' => array( Plugin::PLUGINS_FORUM_ID, Plugin::REVIEWS_FORUM_ID ), |
| | 66 | 'post_status' => 'publish', |
| | 67 | 'tax_query' => array( array( |
| | 68 | 'taxonomy' => 'topic-plugin', |
| | 69 | 'field' => 'slug', |
| | 70 | 'terms' => $this->get_plugin_slugs_by_committer( $this->query['wporg_user_login'] ), |
| | 71 | ) ), |
| | 72 | 'show_stickies' => false, |
| | 73 | 'orderby' => 'ID', |
| | 74 | ); |
| | 75 | break; |
| | 76 | } |
| | 77 | return $retval; |
| | 78 | } |
| | 79 | |
| | 80 | public function parse_query() { |
| | 81 | $user_login = get_query_var( 'wporg_user_login' ); |
| | 82 | $view = get_query_var( 'bbp_view' ); |
| | 83 | if ( ! $user_login || ! $view ) { |
| | 84 | return; |
| | 85 | } |
| | 86 | |
| | 87 | // Basic setup. |
| | 88 | $this->user_login = $user_login; |
| | 89 | |
| | 90 | if ( $view == 'plugin-committer' ) { |
| | 91 | |
| | 92 | $slugs = $this->get_plugin_slugs_by_committer( $user_login ); |
| | 93 | |
| | 94 | // Add plugin-committer view. |
| | 95 | bbp_register_view( |
| | 96 | 'plugin-committer', |
| | 97 | sprintf( __( 'Plugin Committer » %s', 'wporg-forums' ), esc_html( $user_login ) ), |
| | 98 | array( |
| | 99 | 'post_parent__in' => array( Plugin::PLUGINS_FORUM_ID, Plugin::REVIEWS_FORUM_ID ), |
| | 100 | 'post_status' => 'publish', |
| | 101 | 'tax_query' => array( array( |
| | 102 | 'taxonomy' => 'topic-plugin', |
| | 103 | 'field' => 'slug', |
| | 104 | 'terms' => $slugs, |
| | 105 | ) ), |
| | 106 | 'show_stickies' => false, |
| | 107 | ) |
| | 108 | ); |
| | 109 | |
| | 110 | // Add output filters and actions. |
| | 111 | add_filter( 'bbp_get_view_link', array( $this, 'get_view_link' ), 10, 2 ); |
| | 112 | } |
| | 113 | } |
| | 114 | |
| | 115 | public function add_query_var( $query_vars ) { |
| | 116 | $query_vars[] = 'wporg_user_login'; |
| | 117 | return $query_vars; |
| | 118 | } |
| | 119 | |
| | 120 | public function add_rewrite_rules() { |
| | 121 | $priority = 'top'; |
| | 122 | |
| | 123 | $plugin_committer_rule = bbp_get_view_slug() . '/plugin-committer/([^/]+)/'; |
| | 124 | |
| | 125 | $feed_id = 'feed'; |
| | 126 | $view_id = bbp_get_view_rewrite_id(); |
| | 127 | $paged_id = bbp_get_paged_rewrite_id(); |
| | 128 | |
| | 129 | $feed_slug = 'feed'; |
| | 130 | $paged_slug = bbp_get_paged_slug(); |
| | 131 | |
| | 132 | $base_rule = '?$'; |
| | 133 | $feed_rule = $feed_slug . '/?$'; |
| | 134 | $paged_rule = $paged_slug . '/?([0-9]{1,})/?$'; |
| | 135 | |
| | 136 | // Add plugin committer rewrite rules. |
| | 137 | add_rewrite_rule( $plugin_committer_rule . $base_rule, 'index.php?' . $view_id . '=plugin-committer&wporg_user_login=$matches[1]', $priority ); |
| | 138 | add_rewrite_rule( $plugin_committer_rule . $paged_rule, 'index.php?' . $view_id . '=plugin-committer&wporg_user_login=$matches[1]&' . $paged_id . '=$matches[2]', $priority ); |
| | 139 | add_rewrite_rule( $plugin_committer_rule . $feed_rule, 'index.php?' . $view_id . '=plugin-committer&wporg_user_login=$matches[1]&' . $feed_id . '=$matches[2]', $priority ); |
| | 140 | } |
| | 141 | |
| | 142 | /** |
| | 143 | * Filter view links to provide prettier links for the custom view structure. |
| | 144 | */ |
|