Changeset 10523 for trunk/src/bp-notifications/bp-notifications-loader.php
- Timestamp:
- 02/05/2016 05:26:45 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/bp-notifications-loader.php
r10429 r10523 13 13 defined( 'ABSPATH' ) || exit; 14 14 15 /** 16 * Extends the component class to set up the Notifications component. 17 */ 18 class BP_Notifications_Component extends BP_Component { 19 20 /** 21 * Start the notifications component creation process. 22 * 23 * @since 1.9.0 24 */ 25 public function __construct() { 26 parent::start( 27 'notifications', 28 _x( 'Notifications', 'Page <title>', 'buddypress' ), 29 buddypress()->plugin_dir, 30 array( 31 'adminbar_myaccount_order' => 30 32 ) 33 ); 34 } 35 36 /** 37 * Include notifications component files. 38 * 39 * @since 1.9.0 40 * 41 * @see BP_Component::includes() for a description of arguments. 42 * 43 * @param array $includes See BP_Component::includes() for a description. 44 */ 45 public function includes( $includes = array() ) { 46 $includes = array( 47 'actions', 48 'classes', 49 'screens', 50 'adminbar', 51 'template', 52 'functions', 53 'cache', 54 ); 55 56 parent::includes( $includes ); 57 } 58 59 /** 60 * Set up component global data. 61 * 62 * @since 1.9.0 63 * 64 * @see BP_Component::setup_globals() for a description of arguments. 65 * 66 * @param array $args See BP_Component::setup_globals() for a description. 67 */ 68 public function setup_globals( $args = array() ) { 69 $bp = buddypress(); 70 71 // Define a slug, if necessary. 72 if ( ! defined( 'BP_NOTIFICATIONS_SLUG' ) ) { 73 define( 'BP_NOTIFICATIONS_SLUG', $this->id ); 74 } 75 76 // Global tables for the notifications component. 77 $global_tables = array( 78 'table_name' => $bp->table_prefix . 'bp_notifications', 79 'table_name_meta' => $bp->table_prefix . 'bp_notifications_meta', 80 ); 81 82 // All globals for the notifications component. 83 // Note that global_tables is included in this array. 84 $args = array( 85 'slug' => BP_NOTIFICATIONS_SLUG, 86 'has_directory' => false, 87 'search_string' => __( 'Search Notifications...', 'buddypress' ), 88 'global_tables' => $global_tables, 89 ); 90 91 parent::setup_globals( $args ); 92 } 93 94 /** 95 * Set up component navigation. 96 * 97 * @since 1.9.0 98 * 99 * @see BP_Component::setup_nav() for a description of arguments. 100 * 101 * @param array $main_nav Optional. See BP_Component::setup_nav() for 102 * description. 103 * @param array $sub_nav Optional. See BP_Component::setup_nav() for 104 * description. 105 */ 106 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 107 108 // Determine user to use. 109 if ( bp_displayed_user_domain() ) { 110 $user_domain = bp_displayed_user_domain(); 111 } elseif ( bp_loggedin_user_domain() ) { 112 $user_domain = bp_loggedin_user_domain(); 113 } else { 114 return; 115 } 116 117 $access = bp_core_can_edit_settings(); 118 $slug = bp_get_notifications_slug(); 119 $notifications_link = trailingslashit( $user_domain . $slug ); 120 121 // Only grab count if we're on a user page and current user has access. 122 if ( bp_is_user() && bp_user_has_access() ) { 123 $count = bp_notifications_get_unread_notification_count( bp_displayed_user_id() ); 124 $class = ( 0 === $count ) ? 'no-count' : 'count'; 125 $nav_name = sprintf( _x( 'Notifications <span class="%s">%s</span>', 'Profile screen nav', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) ); 126 } else { 127 $nav_name = _x( 'Notifications', 'Profile screen nav', 'buddypress' ); 128 } 129 130 // Add 'Notifications' to the main navigation. 131 $main_nav = array( 132 'name' => $nav_name, 133 'slug' => $slug, 134 'position' => 30, 135 'show_for_displayed_user' => $access, 136 'screen_function' => 'bp_notifications_screen_unread', 137 'default_subnav_slug' => 'unread', 138 'item_css_id' => $this->id, 139 ); 140 141 // Add the subnav items to the notifications nav item. 142 $sub_nav[] = array( 143 'name' => _x( 'Unread', 'Notification screen nav', 'buddypress' ), 144 'slug' => 'unread', 145 'parent_url' => $notifications_link, 146 'parent_slug' => $slug, 147 'screen_function' => 'bp_notifications_screen_unread', 148 'position' => 10, 149 'item_css_id' => 'notifications-my-notifications', 150 'user_has_access' => $access, 151 ); 152 153 $sub_nav[] = array( 154 'name' => _x( 'Read', 'Notification screen nav', 'buddypress' ), 155 'slug' => 'read', 156 'parent_url' => $notifications_link, 157 'parent_slug' => $slug, 158 'screen_function' => 'bp_notifications_screen_read', 159 'position' => 20, 160 'user_has_access' => $access, 161 ); 162 163 parent::setup_nav( $main_nav, $sub_nav ); 164 } 165 166 /** 167 * Set up the component entries in the WordPress Admin Bar. 168 * 169 * @since 1.9.0 170 * 171 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav 172 * parameter array. 173 * 174 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a 175 * description. 176 */ 177 public function setup_admin_bar( $wp_admin_nav = array() ) { 178 179 // Menus for logged in user. 180 if ( is_user_logged_in() ) { 181 182 // Setup the logged in user variables. 183 $notifications_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() ); 184 185 // Pending notification requests. 186 $count = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ); 187 if ( ! empty( $count ) ) { 188 $title = sprintf( _x( 'Notifications <span class="count">%s</span>', 'My Account Notification pending', 'buddypress' ), bp_core_number_format( $count ) ); 189 $unread = sprintf( _x( 'Unread <span class="count">%s</span>', 'My Account Notification pending', 'buddypress' ), bp_core_number_format( $count ) ); 190 } else { 191 $title = _x( 'Notifications', 'My Account Notification', 'buddypress' ); 192 $unread = _x( 'Unread', 'My Account Notification sub nav', 'buddypress' ); 193 } 194 195 // Add the "My Account" sub menus. 196 $wp_admin_nav[] = array( 197 'parent' => buddypress()->my_account_menu_id, 198 'id' => 'my-account-' . $this->id, 199 'title' => $title, 200 'href' => $notifications_link 201 ); 202 203 // Unread. 204 $wp_admin_nav[] = array( 205 'parent' => 'my-account-' . $this->id, 206 'id' => 'my-account-' . $this->id . '-unread', 207 'title' => $unread, 208 'href' => $notifications_link 209 ); 210 211 // Read. 212 $wp_admin_nav[] = array( 213 'parent' => 'my-account-' . $this->id, 214 'id' => 'my-account-' . $this->id . '-read', 215 'title' => _x( 'Read', 'My Account Notification sub nav', 'buddypress' ), 216 'href' => trailingslashit( $notifications_link . 'read' ), 217 ); 218 } 219 220 parent::setup_admin_bar( $wp_admin_nav ); 221 } 222 223 /** 224 * Set up the title for pages and <title>. 225 * 226 * @since 1.9.0 227 */ 228 public function setup_title() { 229 230 // Adjust title. 231 if ( bp_is_notifications_component() ) { 232 $bp = buddypress(); 233 234 if ( bp_is_my_profile() ) { 235 $bp->bp_options_title = __( 'Notifications', 'buddypress' ); 236 } else { 237 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 238 'item_id' => bp_displayed_user_id(), 239 'type' => 'thumb', 240 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 241 ) ); 242 $bp->bp_options_title = bp_get_displayed_user_fullname(); 243 } 244 } 245 246 parent::setup_title(); 247 } 248 249 /** 250 * Setup cache groups. 251 * 252 * @since 2.2.0 253 */ 254 public function setup_cache_groups() { 255 256 // Global groups. 257 wp_cache_add_global_groups( array( 258 'bp_notifications', 259 'notification_meta' 260 ) ); 261 262 parent::setup_cache_groups(); 263 } 264 } 15 require dirname( __FILE__ ) . '/classes/class-bp-notifications-component.php'; 265 16 266 17 /**
Note: See TracChangeset
for help on using the changeset viewer.