Changeset 359 for trunk/bp-messages.php
- Timestamp:
- 09/24/2008 05:31:27 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/bp-messages.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-messages.php
r347 r359 94 94 95 95 $bp['messages'] = array( 96 'table_name' => $wpdb->base_prefix . 'bp_messages', 97 'table_name_threads' => $wpdb->base_prefix . 'bp_messages_threads', 98 'table_name_messages' => $wpdb->base_prefix . 'bp_messages_messages', 99 'table_name_recipients' => $wpdb->base_prefix . 'bp_messages_recipients', 100 'table_name_notices' => $wpdb->base_prefix . 'bp_messages_notices', 101 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-messages/images', 102 'slug' => 'messages' 96 'table_name' => $wpdb->base_prefix . 'bp_messages', 97 'table_name_threads' => $wpdb->base_prefix . 'bp_messages_threads', 98 'table_name_messages' => $wpdb->base_prefix . 'bp_messages_messages', 99 'table_name_recipients' => $wpdb->base_prefix . 'bp_messages_recipients', 100 'table_name_notices' => $wpdb->base_prefix . 'bp_messages_notices', 101 'format_activity_function' => 'messages_format_activity', 102 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-messages/images', 103 'slug' => 'messages' 103 104 ); 104 105 } … … 117 118 global $wpdb, $bp, $userdata; 118 119 119 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {120 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 120 121 //Add the administration tab under the "Site Admin" tab for site administrators 121 122 //add_submenu_page ( 'wpmu-admin.php', __('Messages'), __('Messages'), 1, basename(__FILE__), "messages_settings" ); … … 136 137 function messages_setup_nav() { 137 138 global $bp; 138 139 $nav_key = count($bp['bp_nav']) + 1; 140 141 $bp['bp_nav'][$nav_key] = array( 142 'id' => $bp['messages']['slug'], 143 'name' => 'Messages', 144 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' 145 ); 146 147 $bp['bp_options_nav'][$bp['messages']['slug']] = array( 148 'inbox' => array( 149 'name' => __('Inbox') . $count_indicator, 150 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' ), 151 'sentbox' => array( 152 'name' => __('Sent Messages'), 153 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/sentbox' ), 154 'compose' => array( 155 'name' => __('Compose'), 156 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/compose' ) 157 ); 158 159 if ( is_site_admin() ) { 160 $bp['bp_options_nav'][$bp['messages']['slug']]['notices'] = array( 161 'name' => __('Sent Notices'), 162 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/notices' 163 ); 164 } 165 139 166 140 $inbox_count = BP_Messages_Thread::get_inbox_count(); 167 141 $inbox_display = ( $inbox_count ) ? ' style="display:inline;"' : ' style="display:none;"'; 168 142 $count_indicator = ' <span' . $inbox_display . ' class="unread-count inbox-count">' . BP_Messages_Thread::get_inbox_count() . '</span>'; 143 144 /* Add 'Profile' to the main navigation */ 145 bp_core_add_nav_item( __('Messages'), $bp['messages']['slug'], false, false ); 146 bp_core_add_nav_default( $bp['messages']['slug'], 'messages_screen_inbox', 'inbox' ); 147 148 $messages_link = $bp['loggedin_domain'] . $bp['messages']['slug'] . '/'; 149 150 /* Add the subnav items to the profile */ 151 bp_core_add_subnav_item( $bp['messages']['slug'], 'inbox', __('Inbox') . $count_indicator, $messages_link, 'messages_screen_inbox' ); 152 bp_core_add_subnav_item( $bp['messages']['slug'], 'sentbox', __('Sent Messages'), $messages_link, 'messages_screen_sentbox' ); 153 bp_core_add_subnav_item( $bp['messages']['slug'], 'compose', __('Compose'), $messages_link, 'messages_screen_compose' ); 154 bp_core_add_subnav_item( $bp['messages']['slug'], 'notices', __('Notices'), $messages_link, 'messages_screen_notices', false, true, true ); 169 155 170 156 if ( $bp['current_component'] == $bp['messages']['slug'] ) { … … 173 159 } else { 174 160 $bp_options_avatar = bp_core_get_avatar( $bp['current_userid'], 1 ); 175 $bp['bp_options_title'] = bp_user_fullname( $bp['current_userid'], false );161 $bp['bp_options_title'] = $bp['current_fullname']; 176 162 } 177 163 } … … 179 165 add_action( 'wp', 'messages_setup_nav', 2 ); 180 166 181 182 /************************************************************************** 183 messages_catch_action() 167 /***** Screens **********/ 168 169 function messages_screen_inbox() { 170 bp_catch_uri( 'messages/index' ); 171 } 172 173 function messages_screen_sentbox() { 174 bp_catch_uri( 'messages/sentbox' ); 175 } 176 177 function messages_screen_compose() { 178 bp_catch_uri( 'messages/compose' ); 179 } 180 181 function messages_screen_notices() { 182 global $bp, $notice_id; 183 184 if ( !is_site_admin() ) 185 return false; 186 187 $notice_id = $bp['action_variables'][1]; 188 189 if ( !$notice_id || !is_numeric($notice_id) ) { 190 $bp['current_action'] = 'notices'; 191 bp_catch_uri( 'messages/notices' ); 192 } else { 193 $notice = new BP_Messages_Notice($notice_id); 194 195 if ( $bp['action_variables'][0] == 'deactivate' ) { 196 if ( !$notice->deactivate() ) { 197 $bp['message'] = __('There was a problem deactivating that notice.'); 198 } else { 199 $bp['message'] = __('Notice deactivated.'); 200 $bp['message_type'] = 'success'; 201 } 202 } else if ( $bp['action_variables'][0] == 'activate' ) { 203 if ( !$notice->activate() ) { 204 $bp['message'] = __('There was a problem activating that notice.'); 205 } else { 206 $bp['message'] = __('Notice activated.'); 207 $bp['message_type'] = 'success'; 208 } 209 } else if ( $bp['action_variables'][0] == 'delete' ) { 210 if ( !$notice->delete() ) { 211 $bp['message'] = __('There was a problem deleting that notice.'); 212 } else { 213 $bp['message'] = __('Notice deleted.'); 214 $bp['message_type'] = 'success'; 215 } 216 } 217 } 218 219 add_action( 'template_notices', 'bp_core_render_notice' ); 220 bp_catch_uri( 'messages/notices' ); 221 } 222 223 /***** Actions **********/ 224 225 function messages_action_view_message() { 226 global $bp, $thread_id; 227 228 if ( $bp['current_component'] != $bp['messages']['slug'] || $bp['current_action'] != 'view' ) 229 return false; 230 231 $thread_id = $bp['action_variables'][0]; 232 233 if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) { 234 $bp['current_action'] = 'inbox'; 235 bp_catch_uri( 'messages/index' ); 236 } else { 237 $bp['bp_options_nav'][$bp['messages']['slug']]['view'] = array( 238 'name' => __('From: ' . BP_Messages_Thread::get_last_sender($thread_id)), 239 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' 240 ); 241 242 bp_catch_uri( 'messages/view' ); 243 } 244 } 245 add_action( 'wp', 'messages_action_view_message', 3 ); 246 247 248 function messages_action_delete_message() { 249 global $bp, $thread_id; 250 251 if ( $bp['current_component'] != $bp['messages']['slug'] || $bp['current_action'] != 'delete' ) 252 return false; 253 254 $thread_id = $bp['action_variables'][0]; 255 256 if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) { 257 $bp['current_action'] = 'inbox'; 258 bp_catch_uri( 'messages/index' ); 259 } else { 260 // delete message 261 if ( !BP_Messages_Thread::delete($thread_id) ) { 262 $bp['message'] = __('There was an error deleting that message.'); 263 add_action( 'template_notices', 'bp_core_render_notice' ); 264 265 $bp['current_action'] = 'inbox'; 266 bp_catch_uri( 'messages/index' ); 267 } else { 268 $bp['message'] = __('Message deleted.'); 269 $bp['message_type'] = 'success'; 270 add_action( 'template_notices', 'bp_core_render_notice' ); 271 272 $bp['current_action'] = 'inbox'; 273 bp_catch_uri( 'messages/index' ); 274 } 275 } 276 } 277 add_action( 'wp', 'messages_action_delete_message', 3 ); 278 279 280 function messages_action_bulk_delete() { 281 global $bp, $thread_ids; 282 283 if ( $bp['current_component'] != $bp['messages']['slug'] || $bp['current_action'] != 'bulk-delete' ) 284 return false; 285 286 $thread_ids = $_POST['thread_ids']; 287 288 if ( !$thread_ids || !BP_Messages_Thread::check_access($thread_ids) ) { 289 $bp['current_action'] = 'inbox'; 290 bp_catch_uri( 'messages/index' ); 291 } else { 292 if ( !BP_Messages_Thread::delete( explode(',', $thread_ids ) ) ) { 293 $message = __('There was an error deleting messages.'); 294 add_action( 'template_notices', 'bp_core_render_notice' ); 295 296 $bp['current_action'] = 'inbox'; 297 bp_catch_uri( 'messages/index' ); 298 } else { 299 $bp['message'] = __('Messages deleted.'); 300 $bp['message_type'] = 'success'; 301 add_action( 'template_notices', 'bp_core_render_notice' ); 302 303 $bp['current_action'] = 'inbox'; 304 bp_catch_uri( 'messages/index' ); 305 } 306 } 307 } 308 add_action( 'wp', 'messages_action_bulk_delete', 3 ); 309 310 311 /************************************************************************** 312 messages_record_activity() 184 313 185 Catch actions via pretty urls. 186 **************************************************************************/ 187 188 function messages_catch_action() { 189 global $current_blog, $bp, $thread_id; 190 191 if ( $bp['current_component'] == $bp['messages']['slug'] && $current_blog->blog_id > 1 && $bp['loggedin_userid'] == $bp['current_userid'] ) { 192 switch ( $bp['current_action'] ) { 193 case 'inbox': 194 bp_catch_uri( 'messages/index' ); 195 break; 196 197 case 'sentbox': 198 bp_catch_uri( 'messages/sentbox' ); 199 break; 200 201 case 'compose': 202 bp_catch_uri( 'messages/compose' ); 203 break; 204 205 case 'view': 206 if ( !empty($bp['action_variables']) ) { 207 $thread_id = $bp['action_variables'][0]; 208 209 if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) { 210 $bp['current_action'] = 'inbox'; 211 bp_catch_uri( 'messages/index' ); 212 } else { 213 $bp['bp_options_nav'][$bp['messages']['slug']]['view'] = array( 214 'name' => __('From: ' . BP_Messages_Thread::get_last_sender($thread_id)), 215 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' 216 ); 217 218 bp_catch_uri( 'messages/view' ); 219 } 220 } 221 break; 222 223 case 'delete': 224 if ( !empty($bp['action_variables']) ) { 225 $thread_id = $bp['action_variables'][0]; 226 227 if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) { 228 $bp['current_action'] = 'inbox'; 229 bp_catch_uri( 'messages/index' ); 230 } else { 231 // delete message 232 if ( !BP_Messages_Thread::delete($thread_id) ) { 233 $bp['message'] = __('There was an error deleting that message.'); 234 add_action( 'template_notices', 'bp_core_render_notice' ); 235 236 $bp['current_action'] = 'inbox'; 237 bp_catch_uri( 'messages/index' ); 238 } else { 239 $bp['message'] = __('Message deleted.'); 240 $bp['message_type'] = 'success'; 241 add_action( 'template_notices', 'bp_core_render_notice' ); 242 243 $bp['current_action'] = 'inbox'; 244 bp_catch_uri( 'messages/index' ); 245 } 246 } 247 } 248 break; 249 250 case 'bulk-delete': 251 $thread_ids = $_POST['thread_ids']; 252 253 if ( !$thread_ids || !BP_Messages_Thread::check_access($thread_ids) ) { 254 $bp['current_action'] = 'inbox'; 255 bp_catch_uri( 'messages/index' ); 256 } else { 257 if ( !BP_Messages_Thread::delete( explode(',', $thread_ids ) ) ) { 258 $message = __('There was an error deleting messages.'); 259 add_action( 'template_notices', 'bp_core_render_notice' ); 260 261 $bp['current_action'] = 'inbox'; 262 bp_catch_uri( 'messages/index' ); 263 } else { 264 $bp['message'] = __('Messages deleted.'); 265 $bp['message_type'] = 'success'; 266 add_action( 'template_notices', 'bp_core_render_notice' ); 267 268 $bp['current_action'] = 'inbox'; 269 bp_catch_uri( 'messages/index' ); 270 } 271 } 272 break; 273 274 case 'notices': 275 if ( is_site_admin() ) { 276 if ( isset($bp['action_variables']) ) { 277 $notice_id = $bp['action_variables'][1]; 278 279 if ( !$notice_id || !is_numeric($notice_id) ) { 280 $bp['current_action'] = 'notices'; 281 bp_catch_uri( 'messages/notices' ); 282 } else { 283 $notice = new BP_Messages_Notice($notice_id); 284 285 if ( $bp['action_variables'][0] == 'deactivate' ) { 286 if ( !$notice->deactivate() ) { 287 $bp['message'] = __('There was a problem deactivating that notice.'); 288 } else { 289 $bp['message'] = __('Notice deactivated.'); 290 $bp['message_type'] = 'success'; 291 } 292 } else if ( $bp['action_variables'][0] == 'activate' ) { 293 if ( !$notice->activate() ) { 294 $bp['message'] = __('There was a problem activating that notice.'); 295 } else { 296 $bp['message'] = __('Notice activated.'); 297 $bp['message_type'] = 'success'; 298 } 299 } else if ( $bp['action_variables'][0] == 'delete' ) { 300 if ( !$notice->delete() ) { 301 $bp['message'] = __('There was a problem deleting that notice.'); 302 } else { 303 $bp['message'] = __('Notice deleted.'); 304 $bp['message_type'] = 'success'; 305 } 306 } 307 } 308 } 309 add_action( 'template_notices', 'bp_core_render_notice' ); 310 bp_catch_uri( 'messages/notices' ); 311 } 312 break; 313 314 default: 315 $bp['current_action'] = 'inbox'; 316 bp_catch_uri( 'messages/index' ); 317 break; 318 } 319 } 320 } 321 add_action( 'wp', 'messages_catch_action', 3 ); 314 Records activity for the logged in user within the friends component so that 315 it will show in the users activity stream (if installed) 316 **************************************************************************/ 317 318 function messages_record_activity( $args = true ) { 319 if ( function_exists('bp_activity_record') ) { 320 extract($args); 321 bp_activity_record( $item_id, $component_name, $component_action, $is_private ); 322 } 323 } 324 325 326 /************************************************************************** 327 messages_format_activity() 328 329 Selects and formats recorded messages component activity. 330 **************************************************************************/ 331 332 function messages_format_activity( $friendship_id, $action, $for_secondary_user = false ) { 333 global $bp; 334 335 switch( $action ) { 336 // no actions set yet. 337 } 338 339 return false; 340 } 322 341 323 342 /************************************************************************** … … 583 602 $message = __('Message sent successfully!') . ' <a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/view/' . $pmessage->thread_id . '">' . __('View Message') . '</a> »'; 584 603 $type = 'success'; 604 605 do_action( 'bp_messages_message_sent', array( 'item_id' => $pmessage->id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1 ) ); 585 606 586 607 if ( $from_ajax ) { … … 677 698 $type = 'error'; 678 699 } 700 701 do_action( 'bp_messages_message_deleted' ); 702 679 703 } 680 704 … … 684 708 685 709 710 /************************************************************************** 711 messages_view_thread() 712 713 Displays a message thread. 714 **************************************************************************/ 715 686 716 function messages_view_thread( $thread_id ) { 687 global $ bp_messages_image_base, $userdata;717 global $userdata; 688 718 689 719 $thread = new BP_Messages_Thread( $thread_id, true );
Note: See TracChangeset
for help on using the changeset viewer.