Ticket #2016: 2016.diff
File 2016.diff, 13.0 KB (added by , 6 years ago) |
---|
-
support-forums/inc/class-support-compat.php
class Support_Compat { 342 342 343 343 // Check the current view. 344 344 if ( bbp_is_single_view() ) { 345 345 $retval = ( bbp_get_view_id() != 'reviews' ); 346 346 } 347 347 348 348 return $retval; 349 349 } 350 350 351 351 /** 352 352 * Enable theme and plugin subscriptions. 353 353 */ 354 354 public function load_compat_subscriptions() { 355 355 if ( class_exists( 'WordPressdotorg\Forums\Term_Subscription\Plugin' ) ) { 356 356 Plugin::get_instance()->plugin_subscriptions = new Term_Subscription\Plugin( array( 357 'taxonomy' => 'topic-plugin', 358 'labels' => array( 357 'taxonomy' => 'topic-plugin', 358 'directory' => Plugin::get_instance()->plugins, 359 'labels' => array( 359 360 'subscribed_header' => __( 'Subscribed Plugins', 'wporg-forums' ), 360 361 'subscribed_user_notice' => __( 'You are not currently subscribed to any plugins.', 'wporg-forums' ), 361 362 'subscribed_anon_notice' => __( 'This user is not currently subscribed to any plugins.', 'wporg-forums' ), 362 363 'receipt' => __( 'You are receiving this email because you are subscribed to a plugin.', 'wporg-forums' ), 363 364 ), 364 365 ) ); 365 366 Plugin::get_instance()->theme_subscriptions = new Term_Subscription\Plugin( array( 366 'taxonomy' => 'topic-theme', 367 'labels' => array( 367 'taxonomy' => 'topic-theme', 368 'directory' => Plugin::get_instance()->themes, 369 'labels' => array( 368 370 'subscribed_header' => __( 'Subscribed Themes', 'wporg-forums' ), 369 371 'subscribed_user_notice' => __( 'You are not currently subscribed to any themes.', 'wporg-forums' ), 370 372 'subscribed_anon_notice' => __( 'This user is not currently subscribed to any themes.', 'wporg-forums' ), 371 373 'receipt' => __( 'You are receiving this email because you are subscribed to a theme.', 'wporg-forums' ), 372 374 ), 373 375 ) ); 374 376 } 375 377 } 376 378 377 379 public static function get_compat_forums() { 378 380 return array( Plugin::PLUGINS_FORUM_ID, Plugin::THEMES_FORUM_ID, Plugin::REVIEWS_FORUM_ID ); 379 381 } 380 382 381 383 public static function is_compat_forum( $post_id = 0 ) { 382 384 if ( empty( $post_id ) ) { 383 385 return false; 384 386 } 385 387 return in_array( $post_id, self::get_compat_forums() ); 386 388 } 387 389 388 390 public static function get_plugin_slugs_by_committer( $user_nicename ) { 389 391 global $wpdb; 390 392 391 393 $prefix = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_'; 392 394 $slugs = $wpdb->get_col( $wpdb->prepare( 393 395 "SELECT post_name 394 396 FROM {$prefix}posts AS p 395 397 LEFT JOIN {$prefix}term_relationships AS tr ON p.ID = tr.object_id 396 LEFT JOIN {$prefix}term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 398 LEFT JOIN {$prefix}term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 397 399 LEFT JOIN {$prefix}terms AS t ON tt.term_id = t.term_id 398 400 WHERE tt.taxonomy = 'plugin_committers' AND p.post_status = 'publish' AND p.post_type = 'plugin' AND t.slug = %s 399 401 ORDER BY p.post_title ASC", 400 402 $user_nicename 401 403 ) ); 402 404 403 405 return $slugs; 404 406 } 405 407 406 408 public static function get_plugin_slugs_by_contributor( $user_nicename ) { 407 409 global $wpdb; 408 410 409 411 $prefix = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_'; 410 412 $slugs = $wpdb->get_col( $wpdb->prepare( 411 413 "SELECT post_name 412 414 FROM {$prefix}posts AS p 413 415 LEFT JOIN {$prefix}term_relationships AS tr ON p.ID = tr.object_id 414 LEFT JOIN {$prefix}term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 416 LEFT JOIN {$prefix}term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 415 417 LEFT JOIN {$prefix}terms AS t ON tt.term_id = t.term_id 416 418 WHERE tt.taxonomy = 'plugin_contributors' AND p.post_status = 'publish' AND p.post_type = 'plugin' AND t.slug = %s 417 419 ORDER BY p.post_title ASC", 418 420 $user_nicename 419 421 ) ); 420 422 421 423 return $slugs; 422 424 } 423 425 424 426 public static function clean_slugs( $slugs ) { 425 427 $cleanslugs = array(); 426 428 foreach ( $slugs as $slug ) { 427 429 $slug = trim( $slug, '/' ); 428 430 if ( ! empty( $slug ) ) { 429 431 $cleanslugs[] = $slug; -
wporg-bbp-term-subscription/inc/class-plugin.php
1 1 <?php 2 2 3 3 namespace WordPressdotorg\Forums\Term_Subscription; 4 4 5 5 class Plugin { 6 6 7 7 /** 8 8 * @todo AJAXify subscription action. 9 9 * @todo Add unsubscribe link to outgoing emails. 10 10 */ 11 11 12 12 private $subscribers = array(); 13 13 14 public $taxonomy = false; 15 public $labels = array(); 14 public $taxonomy = false; 15 public $labels = array(); 16 public $directory = false; 16 17 17 18 const META_KEY = '_bbp_term_subscription'; 18 19 19 20 public function __construct( $args = array() ) { 20 21 $r = wp_parse_args( $args, array( 21 'taxonomy' => 'topic-tag', 22 'labels' => array( 22 'taxonomy' => 'topic-tag', 23 'directory' => false, 24 'labels' => array( 23 25 'subscribed_header' => __( 'Subscribed Topic Tags', 'wporg-forums' ), 24 26 'subscribed_user_notice' => __( 'You are not currently subscribed to any topic tags.', 'wporg-forums' ), 25 27 'subscribed_anon_notice' => __( 'This user is not currently subscribed to any topic tags.', 'wporg-forums' ), 26 28 'receipt' => __( 'You are receiving this email because you are subscribed to a topic tag.', 'wporg-forums'), 27 29 ), 28 30 ) ); 29 31 30 $this->taxonomy = $r['taxonomy']; 31 $this->labels = $r['labels']; 32 $this->taxonomy = $r['taxonomy']; 33 $this->labels = $r['labels']; 34 $this->directory = $r['directory']; 32 35 33 36 add_action( 'bbp_init', array( $this, 'bbp_init' ) ); 34 37 } 35 38 36 39 /** 37 40 * Initialize the plugin. 38 41 */ 39 42 public function bbp_init() { 40 43 // If the user isn't logged in, there will be no topics or replies added. 41 44 if ( ! is_user_logged_in() ) { 42 45 return; 43 46 } 44 47 45 48 if ( ! $this->taxonomy ) { 46 49 return; … … class Plugin { 172 175 // Get users who were already notified and exclude them. 173 176 $forum_subscribers = bbp_get_forum_subscribers( $forum_id, true ); 174 177 if ( ! empty( $forum_subscribers ) ) { 175 178 $this->subscribers = array_diff( $this->subscribers, $forum_subscribers ); 176 179 } 177 180 178 181 // Remove the author from being notified of their own topic. 179 182 $this->subscribers = array_diff( $this->subscribers, array( bbp_get_topic_author_id( $topic_id ) ) ); 180 183 181 184 if ( empty( $this->subscribers ) ) { 182 185 return; 183 186 } 184 187 185 188 // Replace forum-specific messaging with term subscription messaging. 186 189 add_filter( 'bbp_forum_subscription_mail_message', array( $this, 'replace_forum_subscription_mail_message' ), 10, 4 ); 190 add_filter( 'bbp_forum_subscription_mail_title', array( $this, 'replace_forum_subscription_mail_title' ), 10, 2 ); 187 191 188 192 // Replace forum subscriber list with term subscribers, avoiding duplicates. 189 193 add_filter( 'bbp_forum_subscription_user_ids', array( $this, 'add_term_subscribers_to_forum' ) ); 190 194 191 195 // Actually notify our term subscribers. 192 196 bbp_notify_forum_subscribers( $topic_id, $forum_id ); 193 197 194 198 // Remove filters. 195 remove_filter( 'bbp_forum_subscription_user_ids', array( $this, 'add_term_subscribers_to_forum' ) );199 remove_filter( 'bbp_forum_subscription_user_ids', array( $this, 'add_term_subscribers_to_forum' ) ); 196 200 remove_filter( 'bbp_forum_subscription_mail_message', array( $this, 'replace_forum_subscription_mail_message' ), 10 ); 201 remove_filter( 'bbp_forum_subscription_mail_title', array( $this, 'replace_forum_subscription_mail_title' ) ); 202 197 203 } 198 204 199 205 /** 200 206 * Temporarily replace the forum subscriber list with any unincluded term subscribers. 201 207 */ 202 208 public function add_term_subscribers_to_forum( $users ) { 203 209 return array_diff( $this->subscribers, $users ); 204 210 } 205 211 206 212 /** 207 213 * Replace the forum subscription message with term-specific messaging. 208 214 * 209 215 * @param string $message The message 210 216 * @param int $topic_id The topic id 211 217 * @param int $forum_id The forum id … … Topic Link: %3$s 230 236 ----------- 231 237 232 238 %4$s 233 239 234 240 Login and visit the topic to reply to the topic or unsubscribe from these emails. Note that replying to this email has no effect.', 'wporg-forums' ), 235 241 $topic_author_name, 236 242 $topic_content, 237 243 $topic_url, 238 244 $this->labels['receipt'] 239 245 ); 240 246 241 247 return $message; 242 248 } 243 249 244 250 /** 251 * Replace the forum subscription subject/title with term-specific messaging. 252 * 253 * @param string $title The current title 254 * @param int $topic_id The topic id 255 * @param int $forum_id The forum id 256 * @param int $user_id The user id 257 */ 258 public function replace_forum_subscription_mail_title( $title, $topic_id ) { 259 if ( $this->directory && $this->directory->title() ) { 260 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 261 $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); 262 263 // [WordPress.org] [Plugin Name] This is my threads 264 $title = sprintf( '[%s] [%s] %s', $blog_name, $this->directory->title(), $topic_title ); 265 } 266 267 return $title; 268 } 269 270 /** 245 271 * Use the existing bbp_notify_topic_subscribers() to send out term subscriptions for replies. 246 272 * Avoid duplicate notifications for topic subscribers through the judicious use of filters within 247 273 * the function. 248 274 * 249 275 * @param int $reply_id The reply id 250 276 * @param int $topic_id The topic id 251 277 * @param int $forum_id The forum id 252 278 * @param mixed $anonymous_data 253 279 * @param int $reply_author 254 280 */ 255 281 public function notify_term_subscribers_of_new_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ) { 256 282 $terms = get_the_terms( $topic_id, $this->taxonomy ); 257 283 if ( ! $terms ) { 258 284 return; 259 285 } … … Login and visit the topic to reply to th 268 294 // Get users who were already notified and exclude them. 269 295 $topic_subscribers = bbp_get_topic_subscribers( $topic_id, true ); 270 296 if ( ! empty( $topic_subscribers ) ) { 271 297 $this->subscribers = array_diff( $this->subscribers, $topic_subscribers ); 272 298 } 273 299 274 300 // Remove the author from being notified of their own reply. 275 301 $this->subscribers = array_diff( $this->subscribers, array( bbp_get_reply_author_id( $reply_id ) ) ); 276 302 277 303 if ( empty( $this->subscribers ) ) { 278 304 return; 279 305 } 280 306 281 307 // Replace topic-specific messaging with term subscription messaging. 282 308 add_filter( 'bbp_subscription_mail_message', array( $this, 'replace_topic_subscription_mail_message' ), 10, 3 ); 309 add_filter( 'bbp_subscription_mail_title', array( $this, 'replace_topic_subscription_mail_title' ), 10, 3 ); 283 310 284 311 // Replace forum subscriber list with term subscribers, avoiding duplicates. 285 312 add_filter( 'bbp_topic_subscription_user_ids', array( $this, 'add_term_subscribers_to_topic' ) ); 286 313 287 314 // Actually notify our term subscribers. 288 315 bbp_notify_topic_subscribers( $reply_id, $topic_id, $forum_id ); 289 316 290 317 // Remove filters. 291 318 remove_filter( 'bbp_topic_subscription_user_ids', array( $this, 'add_term_subscribers_to_topic' ) ); 292 remove_filter( 'bbp_subscription_mail_message', array( $this, 'replace_topic_subscription_mail_message' ), 10 ); 319 remove_filter( 'bbp_subscription_mail_message', array( $this, 'replace_topic_subscription_mail_message' ) ); 320 remove_filter( 'bbp_subscription_mail_title', array( $this, 'replace_topic_subscription_mail_title' ) ); 293 321 } 294 322 295 323 /** 296 324 * Temporarily replace the forum subscriber list with any unincluded term subscribers. 297 325 */ 298 326 public function add_term_subscribers_to_topic( $users ) { 299 327 return array_diff( $this->subscribers, $users ); 300 328 } 301 329 302 330 /** 303 331 * Replace the topic subscription message with term-specific messaging. 304 332 * 305 333 * @param string $message The message 306 334 * @param int $reply_id The reply id 307 335 * @param int $topic_id The topic id … … Reply Link: %3$s 325 353 ----------- 326 354 327 355 %4$s 328 356 329 357 Login and visit the topic to reply to the topic or unsubscribe from these emails. Note that replying to this email has no effect.', 'wporg-forums' ), 330 358 $reply_author_name, 331 359 $reply_content, 332 360 $reply_url, 333 361 $this->labels['receipt'] 334 362 ); 335 363 336 364 return $message; 337 365 } 338 366 339 367 /** 368 * Replace the topic subscription subject/title with term-specific messaging. 369 * 370 * @param string $title The current title 371 * @param int $reply_id The reply id 372 * @param int $topic_id The topic id 373 */ 374 public function replace_topic_subscription_mail_title( $title, $reply_id, $topic_id ) { 375 if ( $this->directory && $this->directory->title() ) { 376 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 377 $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); 378 379 // [WordPress.org] [Plugin Name] This is my threads 380 $title = sprintf( '[%s] [%s] %s', $blog_name, $this->directory->title(), $topic_title ); 381 } 382 383 return $title; 384 } 385 386 /** 340 387 * Add a term subscription block to the user's profile. 341 388 */ 342 389 public function user_subscriptions() { 343 390 $user_id = bbp_get_user_id(); 344 391 if ( empty( $user_id ) ) { 345 392 return; 346 393 } 347 394 $terms = self::get_user_taxonomy_subscriptions( $user_id, $this->taxonomy ); 348 395 ?> 349 396 350 397 <div class="bbp-user-subscriptions"> 351 398 <h2 class="entry-title"><?php echo esc_html( $this->labels['subscribed_header'] ); ?></h2> 352 399 <div class="bbp-user-section"> 353 400 <?php 354 401 if ( $terms ) {