Changeset 10522 for trunk/src/bp-messages/bp-messages-loader.php
- Timestamp:
- 02/05/2016 05:22:55 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/bp-messages-loader.php
r10417 r10522 13 13 defined( 'ABSPATH' ) || exit; 14 14 15 /** 16 * Implementation of BP_Component for the Messages component. 17 * 18 * @since 1.5.0 19 */ 20 class BP_Messages_Component extends BP_Component { 21 22 /** 23 * If this is true, the Message autocomplete will return friends only, unless 24 * this is set to false, in which any matching users will be returned. 25 * 26 * @since 1.5.0 27 * @var bool 28 */ 29 public $autocomplete_all; 30 31 /** 32 * Start the messages component creation process. 33 * 34 * @since 1.5.0 35 */ 36 public function __construct() { 37 parent::start( 38 'messages', 39 __( 'Private Messages', 'buddypress' ), 40 buddypress()->plugin_dir, 41 array( 42 'adminbar_myaccount_order' => 50, 43 'features' => array( 'star' ) 44 ) 45 ); 46 } 47 48 /** 49 * Include files. 50 * 51 * @since 1.5.0 52 * 53 * @param array $includes See {BP_Component::includes()} for details. 54 */ 55 public function includes( $includes = array() ) { 56 57 // Files to include. 58 $includes = array( 59 'cssjs', 60 'cache', 61 'actions', 62 'screens', 63 'classes', 64 'filters', 65 'template', 66 'functions', 67 'notifications', 68 'widgets', 69 ); 70 71 // Conditional includes. 72 if ( bp_is_active( $this->id, 'star' ) ) { 73 $includes[] = 'star'; 74 } 75 76 parent::includes( $includes ); 77 } 78 79 /** 80 * Set up globals for the Messages component. 81 * 82 * The BP_MESSAGES_SLUG constant is deprecated, and only used here for 83 * backwards compatibility. 84 * 85 * @since 1.5.0 86 * 87 * @param array $args Not used. 88 */ 89 public function setup_globals( $args = array() ) { 90 $bp = buddypress(); 91 92 // Define a slug, if necessary. 93 if ( ! defined( 'BP_MESSAGES_SLUG' ) ) { 94 define( 'BP_MESSAGES_SLUG', $this->id ); 95 } 96 97 // Global tables for messaging component. 98 $global_tables = array( 99 'table_name_notices' => $bp->table_prefix . 'bp_messages_notices', 100 'table_name_messages' => $bp->table_prefix . 'bp_messages_messages', 101 'table_name_recipients' => $bp->table_prefix . 'bp_messages_recipients', 102 'table_name_meta' => $bp->table_prefix . 'bp_messages_meta', 103 ); 104 105 // Metadata tables for messaging component. 106 $meta_tables = array( 107 'message' => $bp->table_prefix . 'bp_messages_meta', 108 ); 109 110 $this->autocomplete_all = defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ); 111 112 // All globals for messaging component. 113 // Note that global_tables is included in this array. 114 parent::setup_globals( array( 115 'slug' => BP_MESSAGES_SLUG, 116 'has_directory' => false, 117 'notification_callback' => 'messages_format_notifications', 118 'search_string' => __( 'Search Messages...', 'buddypress' ), 119 'global_tables' => $global_tables, 120 'meta_tables' => $meta_tables 121 ) ); 122 } 123 124 /** 125 * Set up navigation for user pages. 126 * 127 * @param array $main_nav See {BP_Component::setup_nav()} for details. 128 * @param array $sub_nav See {BP_Component::setup_nav()} for details. 129 */ 130 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 131 132 // Determine user to use. 133 if ( bp_displayed_user_domain() ) { 134 $user_domain = bp_displayed_user_domain(); 135 } elseif ( bp_loggedin_user_domain() ) { 136 $user_domain = bp_loggedin_user_domain(); 137 } else { 138 return; 139 } 140 141 $access = bp_core_can_edit_settings(); 142 $slug = bp_get_messages_slug(); 143 $messages_link = trailingslashit( $user_domain . $slug ); 144 145 // Only grab count if we're on a user page and current user has access. 146 if ( bp_is_user() && bp_user_has_access() ) { 147 $count = bp_get_total_unread_messages_count(); 148 $class = ( 0 === $count ) ? 'no-count' : 'count'; 149 $nav_name = sprintf( __( 'Messages <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) ); 150 } else { 151 $nav_name = __( 'Messages', 'buddypress' ); 152 } 153 154 // Add 'Messages' to the main navigation. 155 $main_nav = array( 156 'name' => $nav_name, 157 'slug' => $slug, 158 'position' => 50, 159 'show_for_displayed_user' => $access, 160 'screen_function' => 'messages_screen_inbox', 161 'default_subnav_slug' => 'inbox', 162 'item_css_id' => $this->id 163 ); 164 165 // Add the subnav items to the profile. 166 $sub_nav[] = array( 167 'name' => __( 'Inbox', 'buddypress' ), 168 'slug' => 'inbox', 169 'parent_url' => $messages_link, 170 'parent_slug' => $slug, 171 'screen_function' => 'messages_screen_inbox', 172 'position' => 10, 173 'user_has_access' => $access 174 ); 175 176 if ( bp_is_active( $this->id, 'star' ) ) { 177 $sub_nav[] = array( 178 'name' => __( 'Starred', 'buddypress' ), 179 'slug' => bp_get_messages_starred_slug(), 180 'parent_url' => $messages_link, 181 'parent_slug' => $slug, 182 'screen_function' => 'bp_messages_star_screen', 183 'position' => 11, 184 'user_has_access' => $access 185 ); 186 } 187 188 $sub_nav[] = array( 189 'name' => __( 'Sent', 'buddypress' ), 190 'slug' => 'sentbox', 191 'parent_url' => $messages_link, 192 'parent_slug' => $slug, 193 'screen_function' => 'messages_screen_sentbox', 194 'position' => 20, 195 'user_has_access' => $access 196 ); 197 198 $sub_nav[] = array( 199 'name' => __( 'Compose', 'buddypress' ), 200 'slug' => 'compose', 201 'parent_url' => $messages_link, 202 'parent_slug' => $slug, 203 'screen_function' => 'messages_screen_compose', 204 'position' => 30, 205 'user_has_access' => $access 206 ); 207 208 if ( bp_current_user_can( 'bp_moderate' ) ) { 209 $sub_nav[] = array( 210 'name' => __( 'Notices', 'buddypress' ), 211 'slug' => 'notices', 212 'parent_url' => $messages_link, 213 'parent_slug' => $slug, 214 'screen_function' => 'messages_screen_notices', 215 'position' => 90, 216 'user_has_access' => true 217 ); 218 } 219 220 parent::setup_nav( $main_nav, $sub_nav ); 221 } 222 223 /** 224 * Set up the Toolbar. 225 * 226 * @param array $wp_admin_nav See {BP_Component::setup_admin_bar()} for details. 227 */ 228 public function setup_admin_bar( $wp_admin_nav = array() ) { 229 230 // Menus for logged in user. 231 if ( is_user_logged_in() ) { 232 233 // Setup the logged in user variables. 234 $messages_link = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 235 236 // Unread message count. 237 $count = messages_get_unread_count(); 238 if ( !empty( $count ) ) { 239 $title = sprintf( __( 'Messages <span class="count">%s</span>', 'buddypress' ), bp_core_number_format( $count ) ); 240 $inbox = sprintf( __( 'Inbox <span class="count">%s</span>', 'buddypress' ), bp_core_number_format( $count ) ); 241 } else { 242 $title = __( 'Messages', 'buddypress' ); 243 $inbox = __( 'Inbox', 'buddypress' ); 244 } 245 246 // Add main Messages menu. 247 $wp_admin_nav[] = array( 248 'parent' => buddypress()->my_account_menu_id, 249 'id' => 'my-account-' . $this->id, 250 'title' => $title, 251 'href' => $messages_link 252 ); 253 254 // Inbox. 255 $wp_admin_nav[] = array( 256 'parent' => 'my-account-' . $this->id, 257 'id' => 'my-account-' . $this->id . '-inbox', 258 'title' => $inbox, 259 'href' => $messages_link 260 ); 261 262 // Starred. 263 if ( bp_is_active( $this->id, 'star' ) ) { 264 $wp_admin_nav[] = array( 265 'parent' => 'my-account-' . $this->id, 266 'id' => 'my-account-' . $this->id . '-starred', 267 'title' => __( 'Starred', 'buddypress' ), 268 'href' => trailingslashit( $messages_link . bp_get_messages_starred_slug() ) 269 ); 270 } 271 272 // Sent Messages. 273 $wp_admin_nav[] = array( 274 'parent' => 'my-account-' . $this->id, 275 'id' => 'my-account-' . $this->id . '-sentbox', 276 'title' => __( 'Sent', 'buddypress' ), 277 'href' => trailingslashit( $messages_link . 'sentbox' ) 278 ); 279 280 // Compose Message. 281 $wp_admin_nav[] = array( 282 'parent' => 'my-account-' . $this->id, 283 'id' => 'my-account-' . $this->id . '-compose', 284 'title' => __( 'Compose', 'buddypress' ), 285 'href' => trailingslashit( $messages_link . 'compose' ) 286 ); 287 288 // Site Wide Notices. 289 if ( bp_current_user_can( 'bp_moderate' ) ) { 290 $wp_admin_nav[] = array( 291 'parent' => 'my-account-' . $this->id, 292 'id' => 'my-account-' . $this->id . '-notices', 293 'title' => __( 'All Member Notices', 'buddypress' ), 294 'href' => trailingslashit( $messages_link . 'notices' ) 295 ); 296 } 297 } 298 299 parent::setup_admin_bar( $wp_admin_nav ); 300 } 301 302 /** 303 * Set up the title for pages and <title>. 304 */ 305 public function setup_title() { 306 307 if ( bp_is_messages_component() ) { 308 $bp = buddypress(); 309 310 if ( bp_is_my_profile() ) { 311 $bp->bp_options_title = __( 'My Messages', 'buddypress' ); 312 } else { 313 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 314 'item_id' => bp_displayed_user_id(), 315 'type' => 'thumb', 316 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 317 ) ); 318 $bp->bp_options_title = bp_get_displayed_user_fullname(); 319 } 320 } 321 322 parent::setup_title(); 323 } 324 325 /** 326 * Setup cache groups 327 * 328 * @since 2.2.0 329 */ 330 public function setup_cache_groups() { 331 332 // Global groups. 333 wp_cache_add_global_groups( array( 334 'bp_messages', 335 'bp_messages_threads', 336 'bp_messages_unread_count', 337 'message_meta' 338 ) ); 339 340 parent::setup_cache_groups(); 341 } 342 } 15 require dirname( __FILE__ ) . '/classes/class-bp-messages-component.php'; 343 16 344 17 /**
Note: See TracChangeset
for help on using the changeset viewer.