PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/achievements/includes/extensions/bbpress.php

https://github.com/bfay/maniacal-kitten
PHP | 156 lines | 85 code | 17 blank | 54 comment | 7 complexity | 6d33770a3fa42c9cce2f1309d73a85a5 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Extension for bbPress
  4. *
  5. * This file extends Achievements to support actions from bbPress.
  6. *
  7. * @package Achievements
  8. * @subpackage ExtensionbbPress
  9. */
  10. // Exit if accessed directly
  11. if ( ! defined( 'ABSPATH' ) ) exit;
  12. /**
  13. * Extends Achievements to support actions from bbPress
  14. *
  15. * @since Achievements (3.0)
  16. */
  17. function dpa_init_bbpress_extension() {
  18. achievements()->extensions->bbpress = new DPA_bbPress_Forum_Extension;
  19. // Tell the world that the bbPress extension is ready
  20. do_action( 'dpa_init_bbpress_extension' );
  21. }
  22. add_action( 'dpa_ready', 'dpa_init_bbpress_extension' );
  23. /**
  24. * Extension to add bbPress support to Achievements
  25. *
  26. * @since Achievements (3.0)
  27. */
  28. class DPA_bbPress_Forum_Extension extends DPA_CPT_Extension {
  29. /**
  30. * Constructor
  31. *
  32. * Sets up extension properties. See class phpdoc for details.
  33. *
  34. * @since Achievements (3.0)
  35. */
  36. public function __construct() {
  37. $this->actions = array(
  38. // Forum
  39. 'bbp_deleted_forum' => __( 'A forum is permanently deleted by the user', 'dpa' ),
  40. 'bbp_edit_forum' => __( "A forum&#8217;s settings are changed by the user", 'dpa' ),
  41. 'bbp_new_forum' => __( 'The user creates a new forum', 'dpa' ),
  42. 'bbp_trashed_forum' => __( 'The user puts a forum into the trash', 'dpa' ),
  43. 'bbp_untrashed_forum' => __( 'The user restores a forum from the trash', 'dpa' ),
  44. // Topic management
  45. 'bbp_closed_topic' => __( 'The user closes a topic.', 'dpa' ),
  46. 'bbp_merged_topic' => __( 'Separate topics are merged together by a user', 'dpa' ),
  47. 'bbp_opened_topic' => __( 'The user opens a topic for new replies', 'dpa' ),
  48. 'bbp_post_split_topic' => __( 'An existing topic is split into seperate threads by a user', 'dpa' ),
  49. // Topic
  50. 'bbp_deleted_topic' => __( 'The user permanently deletes a topic', 'dpa' ),
  51. 'bbp_sticked_topic' => __( 'The user marks a topic as a sticky', 'dpa' ),
  52. 'bbp_trashed_topic' => __( 'The user trashes a topic', 'dpa' ),
  53. 'bbp_unsticked_topic' => __( 'The user unstickies a topic', 'dpa' ),
  54. 'bbp_untrashed_topic' => __( 'The user restores a topic from the trash', 'dpa' ),
  55. 'bbpress_topic_draft_to_publish' => __( 'The user creates a new topic.', 'dpa' ),
  56. // Reply
  57. 'bbp_deleted_reply' => __( 'The user permanently deletes a reply', 'dpa' ),
  58. 'bbp_trashed_reply' => __( 'The user trashes a reply', 'dpa' ),
  59. 'bbp_untrashed_reply' => __( 'The user restores a reply from the trash', 'dpa' ),
  60. 'bbpress_reply_draft_to_publish' => __( 'The user replies to a topic.', 'dpa' ),
  61. );
  62. $this->contributors = array(
  63. array(
  64. 'name' => 'Matt',
  65. 'gravatar_url' => 'http://www.gravatar.com/avatar/767fc9c115a1b989744c755db47feb60',
  66. 'profile_url' => 'http://profiles.wordpress.org/matt/',
  67. ),
  68. array(
  69. 'name' => 'John James Jacoby',
  70. 'gravatar_url' => 'http://www.gravatar.com/avatar/81ec16063d89b162d55efe72165c105f',
  71. 'profile_url' => 'http://profiles.wordpress.org/johnjamesjacoby/',
  72. ),
  73. array(
  74. 'name' => 'Jennifer M. Dodd',
  75. 'gravatar_url' => 'http://www.gravatar.com/avatar/6a7c997edea340616bcc6d0fe03f65dd',
  76. 'profile_url' => 'http://profiles.wordpress.org/jmdodd/',
  77. ),
  78. );
  79. $this->generic_cpt_actions = array(
  80. 'draft_to_publish',
  81. 'future_to_publish',
  82. 'new_to_publish',
  83. 'pending_to_publish',
  84. 'private_to_publish',
  85. );
  86. $this->description = __( 'bbPress is forum software, made the WordPress way.', 'dpa' );
  87. $this->id = 'bbpress';
  88. $this->image_url = trailingslashit( achievements()->includes_url ) . 'admin/images/bbpress.png';
  89. $this->name = __( 'bbPress', 'dpa' );
  90. $this->rss_url = 'http://bbpress.org/blog/feed/';
  91. $this->small_image_url = trailingslashit( achievements()->includes_url ) . 'admin/images/bbpress-small.png';
  92. $this->version = 1;
  93. $this->wporg_url = 'http://wordpress.org/extend/plugins/bbpress/';
  94. add_filter( 'dpa_filter_events', array( $this, 'get_generic_cpt_actions' ), 1, 1 );
  95. add_filter( 'dpa_handle_event_name', array( $this, 'event_name' ), 10, 2 );
  96. add_filter( 'dpa_handle_event_user_id', array( $this, 'event_user_id' ), 10, 3 );
  97. }
  98. /**
  99. * Filters the event name which is currently being processed
  100. *
  101. * @param string $event_name Action name
  102. * @param array $func_args Optional; action's arguments, from func_get_args().
  103. * @return string|bool Action name or false to skip any further processing
  104. * @since Achievements (3.0)
  105. */
  106. function event_name( $event_name, $func_args ) {
  107. // Check we're dealing with the right type of event
  108. if ( ! in_array( $event_name, $this->generic_cpt_actions ) )
  109. return $event_name;
  110. // Switch the event name for Replies
  111. if ( 'reply' == $func_args[0]->post_type )
  112. return 'bbpress_reply_draft_to_publish';
  113. // Switch the event name for Topics
  114. elseif ( 'topic' == $func_args[0]->post_type )
  115. return 'bbpress_topic_draft_to_publish';
  116. // The event is a generic post type action which isn't handled by this extension. Bail out.
  117. else
  118. return $event_name;
  119. }
  120. /**
  121. * For some actions from bbPress, get the user ID from the Post's author.
  122. *
  123. * @param int $user_id
  124. * @param string $action_name
  125. * @param array $action_func_args The action's arguments from func_get_args().
  126. * @return int|false New user ID or false to skip any further processing
  127. * @since Achievements (3.0)
  128. */
  129. public function event_user_id( $user_id, $action_name, $action_func_args ) {
  130. // Only deal with events added by this extension.
  131. if ( ! in_array( $action_name, array( 'bbpress_reply_draft_to_publish', 'bbpress_topic_draft_to_publish', ) ) )
  132. return $user_id;
  133. // New Reply or Topic, get the post author
  134. if ( in_array( $action_func_args[0]->post_type, array( 'reply', 'topic', ) ) )
  135. return $this->get_post_author( $user_id, $action_name, $action_func_args );
  136. else
  137. return $user_id;
  138. }
  139. }