[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/extend/buddypress/ -> loader.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress BuddyPress Component Class
   5   *
   6   * bbPress and BuddyPress are designed to connect together seamlessly and
   7   * invisibly, and this is the hunk of code necessary to make that happen.
   8   *
   9   * The code in this BuddyPress Extension does some pretty complicated stuff,
  10   * far outside the realm of the simplicity bbPress is traditionally known for.
  11   *
  12   * While the rest of bbPress serves as an example of how to write pretty, simple
  13   * code, what's in these files is pure madness. It should not be used as an
  14   * example of anything other than successfully juggling chainsaws and puppy-dogs.
  15   *
  16   * @package bbPress
  17   * @subpackage BuddyPress
  18   */
  19  
  20  // Exit if accessed directly
  21  defined( 'ABSPATH' ) || exit;
  22  
  23  if ( ! class_exists( 'BBP_Forums_Component' ) ) :
  24  /**
  25   * Loads Forums Component
  26   *
  27   * @since 2.1.0 bbPress (r3552)
  28   *
  29   * @package bbPress
  30   * @subpackage BuddyPress
  31   */
  32  class BBP_Forums_Component extends BP_Component {
  33  
  34      /**
  35       * Start the forums component creation process
  36       *
  37       * @since 2.1.0 bbPress (r3552)
  38       */
  39  	public function __construct() {
  40          parent::start(
  41              'forums',
  42              esc_html__( 'Forums', 'bbpress' ),
  43              bbpress()->includes_dir . 'extend/buddypress/'
  44          );
  45          $this->includes();
  46          $this->setup_globals();
  47          $this->setup_actions();
  48          $this->fully_loaded();
  49      }
  50  
  51      /**
  52       * Include BuddyPress classes and functions
  53       */
  54  	public function includes( $includes = array() ) {
  55  
  56          // Helper BuddyPress functions
  57          $includes[] = 'functions.php';
  58  
  59          // Members modifications
  60          $includes[] = 'members.php';
  61  
  62          // BuddyPress Notfications Extension functions
  63          if ( bp_is_active( 'notifications' ) ) {
  64              $includes[] = 'notifications.php';
  65          }
  66  
  67          // BuddyPress Activity Extension class
  68          if ( bp_is_active( 'activity' ) ) {
  69              $includes[] = 'activity.php';
  70          }
  71  
  72          // BuddyPress Group Extension class
  73          if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
  74              $includes[] = 'groups.php';
  75          }
  76  
  77          // Require files if they exist
  78          foreach ( $includes as $file ) {
  79              if ( @is_file( $this->path . $file ) ) {
  80                  require $this->path . $file;
  81              }
  82          }
  83  
  84          /**
  85           * Hook for plugins to include files, if necessary.
  86           *
  87           * @since 2.6.0 bbPress (r3552)
  88           */
  89          do_action( "bp_{$this->id}_includes" );
  90      }
  91  
  92      /**
  93       * Setup globals
  94       *
  95       * The BP_FORUMS_SLUG constant is deprecated, and only used here for
  96       * backwards compatibility.
  97       *
  98       * @since 2.1.0 bbPress (r3552)
  99       */
 100  	public function setup_globals( $args = array() ) {
 101          $bp = buddypress();
 102  
 103          // Define the parent forum ID
 104          if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
 105              define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
 106          }
 107  
 108          // Define a slug, if necessary
 109          if ( ! defined( 'BP_FORUMS_SLUG' ) ) {
 110              define( 'BP_FORUMS_SLUG', $this->id );
 111          }
 112  
 113          // All arguments for forums component
 114          $args = array(
 115              'path'          => BP_PLUGIN_DIR,
 116              'slug'          => BP_FORUMS_SLUG,
 117              'root_slug'     => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG,
 118              'has_directory' => false,
 119              'search_string' => esc_html__( 'Search Forums...', 'bbpress' ),
 120          );
 121  
 122          parent::setup_globals( $args );
 123      }
 124  
 125      /**
 126       * Setup the actions
 127       *
 128       * @since 2.0.0 bbPress (r3395)
 129       *
 130       * @access private
 131       * @link https://bbpress.trac.wordpress.org/ticket/2176
 132       */
 133  	public function setup_actions() {
 134  
 135          // Setup the components
 136          add_action( 'bp_init', array( $this, 'setup_components' ), 7 );
 137  
 138          parent::setup_actions();
 139      }
 140  
 141      /**
 142       * Instantiate classes for BuddyPress integration
 143       *
 144       * @since 2.0.0 bbPress (r3395)
 145       */
 146  	public function setup_components() {
 147  
 148          // Always load the members component
 149          bbpress()->extend->buddypress->members = new BBP_BuddyPress_Members();
 150  
 151          // Create new activity class
 152          if ( bp_is_active( 'activity' ) ) {
 153              bbpress()->extend->buddypress->activity = new BBP_BuddyPress_Activity();
 154          }
 155  
 156          // Register the group extension only if groups are active
 157          if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
 158              bp_register_group_extension( 'BBP_Forums_Group_Extension' );
 159          }
 160      }
 161  
 162      /**
 163       * Allow the variables, actions, and filters to be modified by third party
 164       * plugins and themes.
 165       *
 166       * @since 2.1.0 bbPress (r3902)
 167       */
 168  	private function fully_loaded() {
 169          do_action_ref_array( 'bbp_buddypress_loaded', array( $this ) );
 170      }
 171  
 172      /**
 173       * Setup BuddyBar navigation
 174       *
 175       * @since 2.1.0 bbPress (r3552)
 176       */
 177  	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
 178  
 179          // Stop if there is no user displayed or logged in
 180          if ( ! is_user_logged_in() && !bp_displayed_user_id() ) {
 181              return;
 182          }
 183  
 184          // Define local variable(s)
 185          $user_domain = '';
 186  
 187          // Add 'Forums' to the main navigation
 188          $main_nav = array(
 189              'name'                => esc_html__( 'Forums', 'bbpress' ),
 190              'slug'                => $this->slug,
 191              'position'            => 80,
 192              'screen_function'     => 'bbp_member_forums_screen_topics',
 193              'default_subnav_slug' => bbp_get_topic_archive_slug(),
 194              'item_css_id'         => $this->id
 195          );
 196  
 197          // Determine user to use
 198          if ( bp_displayed_user_id() ) {
 199              $user_domain = bp_displayed_user_domain();
 200          } elseif ( bp_loggedin_user_domain() ) {
 201              $user_domain = bp_loggedin_user_domain();
 202          } else {
 203              return;
 204          }
 205  
 206          // User link
 207          $forums_link = trailingslashit( $user_domain . $this->slug );
 208  
 209          // Topics started
 210          $sub_nav[] = array(
 211              'name'            => esc_html__( 'Topics Started', 'bbpress' ),
 212              'slug'            => bbp_get_topic_archive_slug(),
 213              'parent_url'      => $forums_link,
 214              'parent_slug'     => $this->slug,
 215              'screen_function' => 'bbp_member_forums_screen_topics',
 216              'position'        => 20,
 217              'item_css_id'     => 'topics'
 218          );
 219  
 220          // Replies to topics
 221          $sub_nav[] = array(
 222              'name'            => esc_html__( 'Replies Created', 'bbpress' ),
 223              'slug'            => bbp_get_reply_archive_slug(),
 224              'parent_url'      => $forums_link,
 225              'parent_slug'     => $this->slug,
 226              'screen_function' => 'bbp_member_forums_screen_replies',
 227              'position'        => 40,
 228              'item_css_id'     => 'replies'
 229          );
 230  
 231          // Engagements
 232          if ( bbp_is_engagements_active() ) {
 233              $sub_nav[] = array(
 234                  'name'            => esc_html__( 'Engagements', 'bbpress' ),
 235                  'slug'            => bbp_get_user_engagements_slug(),
 236                  'parent_url'      => $forums_link,
 237                  'parent_slug'     => $this->slug,
 238                  'screen_function' => 'bbp_member_forums_screen_engagements',
 239                  'position'        => 60,
 240                  'item_css_id'     => 'engagements'
 241              );
 242          }
 243  
 244          // Favorite topics
 245          if ( bbp_is_favorites_active() ) {
 246              $sub_nav[] = array(
 247                  'name'            => esc_html__( 'Favorites', 'bbpress' ),
 248                  'slug'            => bbp_get_user_favorites_slug(),
 249                  'parent_url'      => $forums_link,
 250                  'parent_slug'     => $this->slug,
 251                  'screen_function' => 'bbp_member_forums_screen_favorites',
 252                  'position'        => 80,
 253                  'item_css_id'     => 'favorites'
 254              );
 255          }
 256  
 257          // Subscribed topics (my profile only)
 258          if ( bp_is_my_profile() && bbp_is_subscriptions_active() ) {
 259              $sub_nav[] = array(
 260                  'name'            => esc_html__( 'Subscriptions', 'bbpress' ),
 261                  'slug'            => bbp_get_user_subscriptions_slug(),
 262                  'parent_url'      => $forums_link,
 263                  'parent_slug'     => $this->slug,
 264                  'screen_function' => 'bbp_member_forums_screen_subscriptions',
 265                  'position'        => 100,
 266                  'item_css_id'     => 'subscriptions'
 267              );
 268          }
 269  
 270          parent::setup_nav( $main_nav, $sub_nav );
 271      }
 272  
 273      /**
 274       * Set up the admin bar
 275       *
 276       * @since 2.1.0 bbPress (r3552)
 277       */
 278  	public function setup_admin_bar( $wp_admin_nav = array() ) {
 279  
 280          // Menus for logged in user
 281          if ( is_user_logged_in() ) {
 282  
 283              // If BuddyPress is network activated and bbPress is
 284              // not activated on a the root blog but on any child one
 285              if ( ! bp_is_root_blog() ) {
 286                  $user_id               = bbp_get_current_user_id();
 287                  $my_account_link       = bbp_get_user_profile_url( $user_id );
 288                  $my_topics_link        = bbp_get_user_topics_created_url( $user_id );
 289                  $my_replies_link       = bbp_get_user_replies_created_url( $user_id );
 290                  $my_engagements_link   = bbp_get_user_engagements_url( $user_id );
 291                  $my_favorites_link     = bbp_get_favorites_permalink( $user_id );
 292                  $my_subscriptions_link = bbp_get_subscriptions_permalink( $user_id );
 293              } else {
 294  
 295                  // Setup the logged in user variables
 296                  $user_domain = bp_loggedin_user_domain();
 297                  $forums_link = trailingslashit( $user_domain . $this->slug );
 298  
 299                  $my_account_link       = trailingslashit( $forums_link );
 300                  $my_topics_link        = trailingslashit( $forums_link . bbp_get_topic_archive_slug() );
 301                  $my_replies_link       = trailingslashit( $forums_link . bbp_get_reply_archive_slug() );
 302                  $my_engagements_link   = trailingslashit( $forums_link . bbp_get_user_engagements_slug() );
 303                  $my_favorites_link     = trailingslashit( $forums_link . bbp_get_user_favorites_slug() );
 304                  $my_subscriptions_link = trailingslashit( $forums_link . bbp_get_user_subscriptions_slug() );
 305              }
 306  
 307              // Add the "My Account" sub menus
 308              $wp_admin_nav[] = array(
 309                  'parent' => buddypress()->my_account_menu_id,
 310                  'id'     => 'my-account-' . $this->id,
 311                  'title'  => esc_html__( 'Forums', 'bbpress' ),
 312                  'href'   => $my_account_link
 313              );
 314  
 315              // Topics
 316              $wp_admin_nav[] = array(
 317                  'parent' => 'my-account-' . $this->id,
 318                  'id'     => 'my-account-' . $this->id . '-topics',
 319                  'title'  => esc_html__( 'Topics Started', 'bbpress' ),
 320                  'href'   => $my_topics_link
 321              );
 322  
 323              // Replies
 324              $wp_admin_nav[] = array(
 325                  'parent' => 'my-account-' . $this->id,
 326                  'id'     => 'my-account-' . $this->id . '-replies',
 327                  'title'  => esc_html__( 'Replies Created', 'bbpress' ),
 328                  'href'   => $my_replies_link
 329              );
 330  
 331              // Engagements
 332              if ( bbp_is_engagements_active() ) {
 333                  $wp_admin_nav[] = array(
 334                      'parent' => 'my-account-' . $this->id,
 335                      'id'     => 'my-account-' . $this->id . '-engagements',
 336                      'title'  => esc_html__( 'Engagements', 'bbpress' ),
 337                      'href'   => $my_engagements_link
 338                  );
 339              }
 340  
 341              // Favorites
 342              if ( bbp_is_favorites_active() ) {
 343                  $wp_admin_nav[] = array(
 344                      'parent' => 'my-account-' . $this->id,
 345                      'id'     => 'my-account-' . $this->id . '-favorites',
 346                      'title'  => esc_html__( 'Favorite Topics', 'bbpress' ),
 347                      'href'   => $my_favorites_link
 348                  );
 349              }
 350  
 351              // Subscriptions
 352              if ( bbp_is_subscriptions_active() ) {
 353                  $wp_admin_nav[] = array(
 354                      'parent' => 'my-account-' . $this->id,
 355                      'id'     => 'my-account-' . $this->id . '-subscriptions',
 356                      'title'  => esc_html__( 'Subscribed Topics', 'bbpress' ),
 357                      'href'   => $my_subscriptions_link
 358                  );
 359              }
 360          }
 361  
 362          parent::setup_admin_bar( $wp_admin_nav );
 363      }
 364  
 365      /**
 366       * Sets up the title for pages and <title>
 367       *
 368       * @since 2.1.0 bbPress (r3552)
 369       */
 370  	public function setup_title() {
 371          $bp = buddypress();
 372  
 373          // Adjust title based on view
 374          if ( bp_is_forums_component() ) {
 375              if ( bp_is_my_profile() ) {
 376                  $bp->bp_options_title = esc_html__( 'Forums', 'bbpress' );
 377              } elseif ( bp_is_user() ) {
 378                  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
 379                      'item_id' => bp_displayed_user_id(),
 380                      'type'    => 'thumb'
 381                  ) );
 382                  $bp->bp_options_title  = bp_get_displayed_user_fullname();
 383              }
 384          }
 385  
 386          parent::setup_title();
 387      }
 388  }
 389  endif;


Generated: Sat Dec 21 01:00:52 2024 Cross-referenced by PHPXref 0.7.1