| 18 | | /** |
| 19 | | * Sets up the forums component. |
| 20 | | * |
| 21 | | * @since 1.5.0 |
| 22 | | */ |
| 23 | | class BP_Forums_Component extends BP_Component { |
| 24 | | |
| 25 | | /** |
| 26 | | * Start the forums component creation process. |
| 27 | | * |
| 28 | | * @since 1.5.0 |
| 29 | | */ |
| 30 | | public function __construct() { |
| 31 | | parent::start( |
| 32 | | 'forums', |
| 33 | | __( 'Discussion Forums', 'buddypress' ), |
| 34 | | buddypress()->plugin_dir, |
| 35 | | array( |
| 36 | | 'adminbar_myaccount_order' => 80 |
| 37 | | ) |
| 38 | | ); |
| 39 | | } |
| 40 | | |
| 41 | | /** |
| 42 | | * Set up bp-forums global settings. |
| 43 | | * |
| 44 | | * The BP_FORUMS_SLUG constant is deprecated, and only used here for |
| 45 | | * backwards compatibility. |
| 46 | | * |
| 47 | | * @since 1.5.0 |
| 48 | | * |
| 49 | | * @see BP_Component::setup_globals() for description of parameters. |
| 50 | | * |
| 51 | | * @param array $args See {@link BP_Component::setup_globals()}. |
| 52 | | */ |
| 53 | | public function setup_globals( $args = array() ) { |
| 54 | | $bp = buddypress(); |
| 55 | | |
| 56 | | // Define the parent forum ID. |
| 57 | | if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) { |
| 58 | | define( 'BP_FORUMS_PARENT_FORUM_ID', 1 ); |
| 59 | | } |
| 60 | | |
| 61 | | // Define a slug, if necessary. |
| 62 | | if ( ! defined( 'BP_FORUMS_SLUG' ) ) { |
| 63 | | define( 'BP_FORUMS_SLUG', $this->id ); |
| 64 | | } |
| 65 | | |
| 66 | | // The location of the bbPress stand-alone config file. |
| 67 | | $bbconfig = bp_core_get_root_option( 'bb-config-location' ); |
| 68 | | if ( '' !== $bbconfig ) { |
| 69 | | $this->bbconfig = $bbconfig; |
| 70 | | } |
| 71 | | |
| 72 | | // All globals for messaging component. |
| 73 | | // Note that global_tables is included in this array. |
| 74 | | $globals = array( |
| 75 | | 'slug' => BP_FORUMS_SLUG, |
| 76 | | 'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG, |
| 77 | | 'has_directory' => true, |
| 78 | | 'notification_callback' => 'messages_format_notifications', |
| 79 | | 'search_string' => __( 'Search Forums...', 'buddypress' ), |
| 80 | | ); |
| 81 | | |
| 82 | | parent::setup_globals( $globals ); |
| 83 | | } |
| 84 | | |
| 85 | | /** |
| 86 | | * Include bp-forums files. |
| 87 | | * |
| 88 | | * @since 1.5.0 |
| 89 | | * |
| 90 | | * @see BP_Component::includes() for description of parameters. |
| 91 | | * |
| 92 | | * @param array $includes See {@link BP_Component::includes()}. |
| 93 | | */ |
| 94 | | public function includes( $includes = array() ) { |
| 95 | | |
| 96 | | // Files to include. |
| 97 | | $includes = array( |
| 98 | | 'actions', |
| 99 | | 'screens', |
| 100 | | 'classes', |
| 101 | | 'filters', |
| 102 | | 'template', |
| 103 | | 'functions', |
| 104 | | ); |
| 105 | | |
| 106 | | // bbPress stand-alone. |
| 107 | | if ( ! defined( 'BB_PATH' ) ) { |
| 108 | | $includes[] = 'bbpress-sa'; |
| 109 | | } |
| 110 | | |
| 111 | | // Admin-specific code. |
| 112 | | if ( is_admin() ) { |
| 113 | | $includes[] = 'deprecated/1.6'; |
| 114 | | $includes[] = 'deprecated/1.7'; |
| 115 | | } |
| 116 | | |
| 117 | | parent::includes( $includes ); |
| 118 | | } |
| 119 | | |
| 120 | | /** |
| 121 | | * Set up component navigation. |
| 122 | | * |
| 123 | | * @since 1.5.0 |
| 124 | | * |
| 125 | | * @see BP_Component::setup_nav() for a description of arguments. |
| 126 | | * |
| 127 | | * @param array $main_nav Optional. See BP_Component::setup_nav() for |
| 128 | | * description. |
| 129 | | * @param array $sub_nav Optional. See BP_Component::setup_nav() for |
| 130 | | * description. |
| 131 | | */ |
| 132 | | public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
| 133 | | |
| 134 | | // Stop if forums haven't been set up yet. |
| 135 | | if ( ! bp_forums_is_installed_correctly() ) { |
| 136 | | return; |
| 137 | | } |
| 138 | | |
| 139 | | // Stop if there is no user displayed or logged in. |
| 140 | | if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { |
| 141 | | return; |
| 142 | | } |
| 143 | | |
| 144 | | // Determine user to use. |
| 145 | | if ( bp_displayed_user_domain() ) { |
| 146 | | $user_domain = bp_displayed_user_domain(); |
| 147 | | } elseif ( bp_loggedin_user_domain() ) { |
| 148 | | $user_domain = bp_loggedin_user_domain(); |
| 149 | | } else { |
| 150 | | return; |
| 151 | | } |
| 152 | | |
| 153 | | // User link. |
| 154 | | $slug = bp_get_forums_slug(); |
| 155 | | $forums_link = trailingslashit( $user_domain . $slug ); |
| 156 | | |
| 157 | | // Add 'Forums' to the main navigation. |
| 158 | | $main_nav = array( |
| 159 | | 'name' => __( 'Forums', 'buddypress' ), |
| 160 | | 'slug' => $slug, |
| 161 | | 'position' => 80, |
| 162 | | 'screen_function' => 'bp_member_forums_screen_topics', |
| 163 | | 'default_subnav_slug' => 'topics', |
| 164 | | 'item_css_id' => $this->id |
| 165 | | ); |
| 166 | | |
| 167 | | // Topics started. |
| 168 | | $sub_nav[] = array( |
| 169 | | 'name' => __( 'Topics Started', 'buddypress' ), |
| 170 | | 'slug' => 'topics', |
| 171 | | 'parent_url' => $forums_link, |
| 172 | | 'parent_slug' => $slug, |
| 173 | | 'screen_function' => 'bp_member_forums_screen_topics', |
| 174 | | 'position' => 20, |
| 175 | | 'item_css_id' => 'topics' |
| 176 | | ); |
| 177 | | |
| 178 | | // Topics replied to. |
| 179 | | $sub_nav[] = array( |
| 180 | | 'name' => __( 'Replied To', 'buddypress' ), |
| 181 | | 'slug' => 'replies', |
| 182 | | 'parent_url' => $forums_link, |
| 183 | | 'parent_slug' => $slug, |
| 184 | | 'screen_function' => 'bp_member_forums_screen_replies', |
| 185 | | 'position' => 40, |
| 186 | | 'item_css_id' => 'replies' |
| 187 | | ); |
| 188 | | |
| 189 | | parent::setup_nav( $main_nav, $sub_nav ); |
| 190 | | } |
| 191 | | |
| 192 | | /** |
| 193 | | * Set up bp-forums integration with the WordPress admin bar. |
| 194 | | * |
| 195 | | * @since 1.5.0 |
| 196 | | * |
| 197 | | * @see BP_Component::setup_admin_bar() for a description of arguments. |
| 198 | | * |
| 199 | | * @param array $wp_admin_nav See BP_Component::setup_admin_bar() |
| 200 | | * for description. |
| 201 | | */ |
| 202 | | public function setup_admin_bar( $wp_admin_nav = array() ) { |
| 203 | | |
| 204 | | // Menus for logged in user. |
| 205 | | if ( is_user_logged_in() ) { |
| 206 | | |
| 207 | | // Setup the logged in user variables. |
| 208 | | $forums_link = trailingslashit( bp_loggedin_user_domain() . bp_get_forums_slug() ); |
| 209 | | |
| 210 | | // Add the "My Account" sub menus. |
| 211 | | $wp_admin_nav[] = array( |
| 212 | | 'parent' => buddypress()->my_account_menu_id, |
| 213 | | 'id' => 'my-account-' . $this->id, |
| 214 | | 'title' => __( 'Forums', 'buddypress' ), |
| 215 | | 'href' => $forums_link |
| 216 | | ); |
| 217 | | |
| 218 | | // Topics. |
| 219 | | $wp_admin_nav[] = array( |
| 220 | | 'parent' => 'my-account-' . $this->id, |
| 221 | | 'id' => 'my-account-' . $this->id . '-topics-started', |
| 222 | | 'title' => __( 'Topics Started', 'buddypress' ), |
| 223 | | 'href' => $forums_link |
| 224 | | ); |
| 225 | | |
| 226 | | // Replies. |
| 227 | | $wp_admin_nav[] = array( |
| 228 | | 'parent' => 'my-account-' . $this->id, |
| 229 | | 'id' => 'my-account-' . $this->id . '-replies', |
| 230 | | 'title' => __( 'Replies', 'buddypress' ), |
| 231 | | 'href' => trailingslashit( $forums_link . 'replies' ) |
| 232 | | ); |
| 233 | | |
| 234 | | // Favorites. |
| 235 | | $wp_admin_nav[] = array( |
| 236 | | 'parent' => 'my-account-' . $this->id, |
| 237 | | 'id' => 'my-account-' . $this->id . '-favorite-topics', |
| 238 | | 'title' => __( 'Favorite Topics', 'buddypress' ), |
| 239 | | 'href' => trailingslashit( $forums_link . 'favorites' ) |
| 240 | | ); |
| 241 | | } |
| 242 | | |
| 243 | | parent::setup_admin_bar( $wp_admin_nav ); |
| 244 | | } |
| 245 | | |
| 246 | | /** |
| 247 | | * Set up the title for pages and the <title> element. |
| 248 | | * |
| 249 | | * @since 1.5.0 |
| 250 | | */ |
| 251 | | public function setup_title() { |
| 252 | | |
| 253 | | // Adjust title based on view. |
| 254 | | if ( bp_is_forums_component() ) { |
| 255 | | $bp = buddypress(); |
| 256 | | |
| 257 | | if ( bp_is_my_profile() ) { |
| 258 | | $bp->bp_options_title = __( 'Forums', 'buddypress' ); |
| 259 | | } else { |
| 260 | | $bp->bp_options_avatar = bp_core_fetch_avatar( array( |
| 261 | | 'item_id' => bp_displayed_user_id(), |
| 262 | | 'type' => 'thumb', |
| 263 | | 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) |
| 264 | | ) ); |
| 265 | | $bp->bp_options_title = bp_get_displayed_user_fullname(); |
| 266 | | } |
| 267 | | } |
| 268 | | |
| 269 | | parent::setup_title(); |
| 270 | | } |
| | 18 | if ( ! buddypress()->do_autoload ) { |
| | 19 | require dirname( __FILE__ ) . '/classes/class-bp-forums-component.php'; |