Changeset 4184
- Timestamp:
- 10/04/2016 04:10:20 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php
r4009 r4184 8 8 class Support_Compat { 9 9 10 var $loaded = false; 10 var $loaded = false; 11 var $query = null; 12 var $user_login = null; 11 13 12 14 public function __construct() { 13 15 if ( ! $this->loaded ) { 16 // Intercept feed requests prior to bbp_request_feed_trap. 17 add_filter( 'bbp_request', array( $this, 'request' ), 9 ); 18 19 // Add views for plugin committer/contributor. 20 add_filter( 'query_vars', array( $this, 'add_query_var' ) ); 21 add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) ); 22 23 // We have to add the custom view before bbPress runs its own action 24 // on parse_query at priority 2. 25 add_action( 'parse_query', array( $this, 'parse_query' ), 0 ); 14 26 15 27 // Exclude compat forums from forum dropdown. … … 24 36 $this->loaded = true; 25 37 } 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 */ 145 public function get_view_link( $url, $view ) { 146 global $wp_rewrite; 147 148 $view = bbp_get_view_id( $view ); 149 if ( ! in_array( $view, array( 'plugin-committer' ) ) ) { 150 return $url; 151 } 152 153 // Pretty permalinks. 154 if ( $wp_rewrite->using_permalinks() ) { 155 $url = $wp_rewrite->root . 'view/plugin-committer/' . $this->user_login; 156 $url = home_url( user_trailingslashit( $url ) ); 157 158 // Unpretty permalinks. 159 } else { 160 $url = add_query_arg( array( 161 bbp_get_view_rewrite_id() => $view, 162 'wporg_user_login' => $this->user_login, 163 ) ); 164 } 165 return $url; 26 166 } 27 167 … … 129 269 return in_array( $post_id, self::get_compat_forums() ); 130 270 } 271 272 public static function get_plugin_slugs_by_committer( $user_login ) { 273 global $wpdb; 274 $slugs = (array) $wpdb->get_col( $wpdb->prepare( "SELECT `path` FROM `" . PLUGINS_TABLE_PREFIX . "svn_access` WHERE `user` = %s AND `access` = 'rw' LIMIT 4", $user_login ) ); 275 return $slugs; 276 } 131 277 }
Note: See TracChangeset
for help on using the changeset viewer.