Changeset 2077 for trunk/bp-messages.php
- Timestamp:
- 11/02/2009 07:54:21 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-messages.php (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-messages.php
r2020 r2077 15 15 if ( !defined( 'BP_IGNORE_DEPRECATED' ) ) 16 16 require ( BP_PLUGIN_DIR . '/bp-messages/deprecated/bp-messages-deprecated.php' ); 17 17 18 18 function messages_install() { 19 19 global $wpdb, $bp; 20 20 21 21 if ( !empty($wpdb->charset) ) 22 22 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 23 23 24 24 $sql[] = "CREATE TABLE {$bp->messages->table_name_threads} ( 25 25 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 33 33 KEY last_sender_id (last_sender_id) 34 34 ) {$charset_collate};"; 35 35 36 36 $sql[] = "CREATE TABLE {$bp->messages->table_name_recipients} ( 37 37 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 56 56 KEY sender_id (sender_id) 57 57 ) {$charset_collate};"; 58 58 59 59 $sql[] = "CREATE TABLE {$bp->messages->table_name_notices} ( 60 60 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 65 65 KEY is_active (is_active) 66 66 ) {$charset_collate};"; 67 67 68 68 require_once( ABSPATH . 'wp-admin/upgrade-functions.php' ); 69 69 dbDelta($sql); 70 70 71 71 add_site_option( 'bp-messages-db-version', BP_MESSAGES_DB_VERSION ); 72 72 } … … 77 77 /* For internal identification */ 78 78 $bp->messages->id = 'messages'; 79 79 80 80 $bp->messages->table_name_threads = $wpdb->base_prefix . 'bp_messages_threads'; 81 81 $bp->messages->table_name_messages = $wpdb->base_prefix . 'bp_messages_messages'; … … 91 91 do_action( 'messages_setup_globals' ); 92 92 } 93 add_action( 'plugins_loaded', 'messages_setup_globals', 5 ); 93 add_action( 'plugins_loaded', 'messages_setup_globals', 5 ); 94 94 add_action( 'admin_menu', 'messages_setup_globals', 2 ); 95 95 96 function messages_check_installed() { 96 function messages_check_installed() { 97 97 global $wpdb, $bp; 98 98 99 99 if ( !is_site_admin() ) 100 100 return false; 101 101 102 102 /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */ 103 103 if ( get_site_option('bp-messages-db-version') < BP_MESSAGES_DB_VERSION ) … … 117 117 /* Add 'Messages' to the main navigation */ 118 118 bp_core_new_nav_item( array( 'name' => __('Messages', 'buddypress'), 'slug' => $bp->messages->slug, 'position' => 50, 'show_for_displayed_user' => false, 'screen_function' => 'messages_screen_inbox', 'default_subnav_slug' => 'inbox', 'item_css_id' => $bp->messages->id ) ); 119 119 120 120 $messages_link = $bp->loggedin_user->domain . $bp->messages->slug . '/'; 121 121 122 122 /* Add the subnav items to the profile */ 123 123 bp_core_new_subnav_item( array( 'name' => __( 'Inbox', 'buddypress' ) . $count_indicator, 'slug' => 'inbox', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_inbox', 'position' => 10, 'user_has_access' => bp_is_home() ) ); 124 124 bp_core_new_subnav_item( array( 'name' => __( 'Sent Messages', 'buddypress' ), 'slug' => 'sentbox', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_sentbox', 'position' => 20, 'user_has_access' => bp_is_home() ) ); 125 125 bp_core_new_subnav_item( array( 'name' => __( 'Compose', 'buddypress' ), 'slug' => 'compose', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_compose', 'position' => 30, 'user_has_access' => bp_is_home() ) ); 126 126 127 127 if ( is_site_admin() ) 128 128 bp_core_new_subnav_item( array( 'name' => __( 'Notices', 'buddypress' ), 'slug' => 'notices', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_notices', 'position' => 90, 'user_has_access' => is_site_admin() ) ); … … 130 130 if ( $bp->current_component == $bp->messages->slug ) { 131 131 if ( bp_is_home() ) { 132 $bp->bp_options_title = __( 'My Messages', 'buddypress' ); 132 $bp->bp_options_title = __( 'My Messages', 'buddypress' ); 133 133 } else { 134 134 $bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); … … 136 136 } 137 137 } 138 138 139 139 do_action( 'messages_setup_nav' ); 140 140 } … … 153 153 function messages_screen_inbox() { 154 154 do_action( 'messages_screen_inbox' ); 155 bp_core_load_template( apply_filters( 'messages_template_inbox', 'messages/index' ) ); 155 bp_core_load_template( apply_filters( 'messages_template_inbox', 'messages/index' ) ); 156 156 } 157 157 … … 163 163 function messages_screen_compose() { 164 164 global $bp; 165 165 166 166 // Remove any saved message data from a previous session. 167 167 messages_remove_callback_values(); … … 169 169 /* Check if the message form has been submitted */ 170 170 if ( isset( $_POST['send'] ) ) { 171 171 172 172 /* Check the nonce */ 173 173 check_admin_referer( 'messages_send_message' ); 174 174 175 175 /* Check we have what we need */ 176 176 if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) { … … 185 185 $typed_recipients = explode( ' ', $_POST['send_to_usernames'] ); 186 186 $recipients = array_merge( (array) $autocomplete_recipients, (array) $typed_recipients ); 187 187 188 188 /* Send the message */ 189 189 if ( $thread_id = messages_new_message( array( 'recipients' => $recipients, 'subject' => $_POST['subject'], 'content' => $_POST['content'] ) ) ) { … … 197 197 198 198 } 199 199 200 200 do_action( 'messages_screen_compose' ); 201 201 202 202 bp_core_load_template( apply_filters( 'messages_template_compose', 'messages/compose' ) ); 203 203 } … … 205 205 function messages_screen_notices() { 206 206 global $bp, $notice_id; 207 207 208 208 if ( !is_site_admin() ) 209 209 return false; 210 210 211 211 $notice_id = $bp->action_variables[1]; 212 212 … … 216 216 if ( 'deactivate' == $bp->action_variables[0] ) { 217 217 if ( !$notice->deactivate() ) { 218 bp_core_add_message( __('There was a problem deactivating that notice.', 'buddypress'), 'error' ); 218 bp_core_add_message( __('There was a problem deactivating that notice.', 'buddypress'), 'error' ); 219 219 } else { 220 220 bp_core_add_message( __('Notice deactivated.', 'buddypress') ); … … 235 235 bp_core_redirect( $bp->loggedin_user->domain . $bp->messages->slug . '/notices' ); 236 236 } 237 237 238 238 do_action( 'messages_screen_notices' ); 239 240 bp_core_load_template( apply_filters( 'messages_template_notices', 'messages/notices' ) ); 241 } 242 243 function messages_screen_notification_settings() { 239 240 bp_core_load_template( apply_filters( 'messages_template_notices', 'messages/notices' ) ); 241 } 242 243 function messages_screen_notification_settings() { 244 244 global $current_user; ?> 245 245 <table class="notification-settings" id="messages-notification-settings"> … … 262 262 <td class="no"><input type="radio" name="notifications[notification_messages_new_notice]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_messages_new_notice' ) ) { ?>checked="checked" <?php } ?>/></td> 263 263 </tr> 264 264 265 265 <?php do_action( 'messages_screen_notification_settings' ) ?> 266 266 </table> 267 <?php 267 <?php 268 268 } 269 269 add_action( 'bp_notification_settings', 'messages_screen_notification_settings', 2 ); … … 280 280 function messages_action_view_message() { 281 281 global $bp, $thread_id; 282 282 283 283 if ( $bp->current_component != $bp->messages->slug || $bp->current_action != 'view' ) 284 284 return false; 285 285 286 286 $thread_id = $bp->action_variables[0]; 287 287 288 288 if ( !$thread_id || !messages_is_valid_thread( $thread_id ) || ( !messages_check_thread_access($thread_id) && !is_site_admin() ) ) 289 289 bp_core_redirect( $bp->displayed_user->domain . $bp->current_component ); 290 290 291 291 /* Check if a new reply has been submitted */ 292 292 if ( isset( $_POST['send'] ) ) { 293 293 294 294 /* Check the nonce */ 295 295 check_admin_referer( 'messages_send_message', 'send_message_nonce' ); 296 296 297 297 /* Send the reply */ 298 298 if ( messages_new_message( array( 'thread_id' => $thread_id, 'subject' => $_POST['subject'], 'content' => $_POST['content'] ) ) ) … … 300 300 else 301 301 bp_core_add_message( __( 'There was a problem sending your reply, please try again', 'buddypress' ), 'error' ); 302 303 bp_core_redirect( $bp->displayed_user->domain . $bp->current_component . '/view/' . $thread_id . '/' ); 304 } 305 302 303 bp_core_redirect( $bp->displayed_user->domain . $bp->current_component . '/view/' . $thread_id . '/' ); 304 } 305 306 306 /* Mark message read */ 307 307 messages_mark_thread_read( $thread_id ); 308 308 309 309 do_action( 'messages_action_view_message' ); 310 310 311 311 bp_core_new_subnav_item( array( 'name' => sprintf( __( 'From: %s', 'buddypress'), BP_Messages_Thread::get_last_sender($thread_id) ), 'slug' => 'view', 'parent_url' => $bp->loggedin_user->domain . $bp->messages->slug . '/', 'parent_slug' => $bp->messages->slug, 'screen_function' => true, 'position' => 40, 'user_has_access' => bp_is_home() ) ); 312 312 bp_core_load_template( apply_filters( 'messages_template_view_message', 'messages/view' ) ); … … 316 316 function messages_action_delete_message() { 317 317 global $bp, $thread_id; 318 318 319 319 if ( $bp->current_component != $bp->messages->slug || 'notices' == $bp->current_action || $bp->action_variables[0] != 'delete' ) 320 320 return false; 321 321 322 322 $thread_id = $bp->action_variables[1]; 323 323 … … 341 341 function messages_action_bulk_delete() { 342 342 global $bp, $thread_ids; 343 343 344 344 if ( $bp->current_component != $bp->messages->slug || $bp->action_variables[0] != 'bulk-delete' ) 345 345 return false; 346 346 347 347 $thread_ids = $_POST['thread_ids']; 348 348 349 349 if ( !$thread_ids || !messages_check_thread_access($thread_ids) ) { 350 bp_core_redirect( $bp->displayed_user->domain . $bp->current_component . '/' . $bp->current_action ); 350 bp_core_redirect( $bp->displayed_user->domain . $bp->current_component . '/' . $bp->current_action ); 351 351 } else { 352 352 if ( !check_admin_referer( 'messages_delete_thread' ) ) 353 353 return false; 354 354 355 355 if ( !messages_delete_thread( $thread_ids ) ) { 356 356 bp_core_add_message( __('There was an error deleting messages.', 'buddypress'), 'error' ); … … 373 373 function messages_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) { 374 374 global $bp; 375 375 376 376 if ( 'new_message' == $action ) { 377 377 if ( (int)$total_items > 1 ) 378 return apply_filters( 'bp_messages_multiple_new_message_notification', '<a href="' . $bp->loggedin_user->domain . $bp->messages->slug . '/inbox" title="Inbox">' . sprintf( __('You have %d new messages', 'buddypress' ), (int)$total_items ) . '</a>', $total_items ); 378 return apply_filters( 'bp_messages_multiple_new_message_notification', '<a href="' . $bp->loggedin_user->domain . $bp->messages->slug . '/inbox" title="Inbox">' . sprintf( __('You have %d new messages', 'buddypress' ), (int)$total_items ) . '</a>', $total_items ); 379 379 else 380 380 return apply_filters( 'bp_messages_single_new_message_notification', '<a href="' . $bp->loggedin_user->domain . $bp->messages->slug . '/inbox" title="Inbox">' . sprintf( __('You have %d new message', 'buddypress' ), (int)$total_items ) . '</a>', $total_items ); 381 381 } 382 382 383 383 do_action( 'messages_format_notifications', $action, $item_id, $secondary_item_id, $total_items ); 384 384 385 385 return false; 386 386 } … … 398 398 function messages_new_message( $args = '' ) { 399 399 global $bp; 400 400 401 401 $defaults = array( 402 402 'thread_id' => false, // false for a new message, thread id for a reply to a thread. … … 409 409 410 410 $r = wp_parse_args( $args, $defaults ); 411 extract( $r, EXTR_SKIP ); 412 411 extract( $r, EXTR_SKIP ); 412 413 413 if ( !$sender_id || !$subject || !$content ) 414 414 return false; 415 416 /* Create a new message object */ 415 416 /* Create a new message object */ 417 417 $message = new BP_Messages_Message; 418 418 $message->thread_id = $thread_id; … … 425 425 if ( $thread_id ) { 426 426 $thread = new BP_Messages_Thread($thread_id); 427 $message->recipients = $thread->get_recipients(); 427 $message->recipients = $thread->get_recipients(); 428 428 } else { 429 429 if ( empty( $recipients ) ) 430 430 return false; 431 431 432 432 /* Loop the recipients and convert all usernames to user_ids where needed */ 433 433 foreach( (array) $recipients as $recipient ) { 434 434 if ( is_numeric( trim( $recipient ) ) ) 435 435 $recipient_ids[] = (int)trim( $recipient ); 436 436 437 437 if ( $recipient_id = bp_core_get_userid( trim( $recipient ) ) ) 438 438 $recipient_ids[] = (int)$recipient_id; … … 445 445 /* Remove duplicates */ 446 446 $recipient_ids = array_unique( (array)$recipient_ids ); 447 447 448 448 if ( empty( $recipient_ids ) ) 449 449 return false; 450 451 $message->recipients = $recipient_ids; 452 } 453 450 451 $message->recipients = $recipient_ids; 452 } 453 454 454 if ( $message->send() ) { 455 455 require_once( BP_PLUGIN_DIR . '/bp-messages/bp-messages-notifications.php' ); … … 457 457 // Send screen notifications to the recipients 458 458 foreach ( (array)$message->recipients as $recipient ) { 459 bp_core_add_notification( $message->id, $recipient, 'messages', 'new_message' ); 460 } 461 459 bp_core_add_notification( $message->id, $recipient, 'messages', 'new_message' ); 460 } 461 462 462 // Send email notifications to the recipients 463 463 messages_notification_new_message( array( 'item_id' => $message->id, 'recipient_ids' => $message->recipients, 'thread_id' => $message->thread_id, 'component_name' => $bp->messages->slug, 'component_action' => 'message_sent', 'is_private' => 1 ) ); 464 464 465 465 do_action( 'messages_message_sent', &$message ); 466 466 467 467 return $message->thread_id; 468 468 } 469 469 470 470 return false; 471 471 } … … 483 483 $notice->is_active = 1; 484 484 $notice->save(); // send it. 485 485 486 486 do_action( 'messages_send_notice', $subject, $message ); 487 487 488 488 return true; 489 489 } … … 497 497 $error = 1; 498 498 } 499 499 500 500 if ( $error ) 501 501 return false; 502 502 503 503 do_action( 'messages_delete_thread', $thread_ids ); 504 504 505 505 return true; 506 506 } else { 507 507 if ( !BP_Messages_Thread::delete($thread_ids) ) 508 508 return false; 509 509 510 510 do_action( 'messages_delete_thread', $thread_ids ); 511 511 512 512 return true; 513 513 } … … 516 516 function messages_check_thread_access( $thread_id, $user_id = false ) { 517 517 global $bp; 518 518 519 519 if ( !$user_id ) 520 520 $user_id = $bp->loggedin_user->id; 521 521 522 522 return BP_Messages_Thread::check_access( $thread_id, $user_id ); 523 523 } … … 528 528 529 529 function messages_mark_thread_unread( $thread_id ) { 530 return BP_Messages_Thread::mark_as_unread( $thread_id ); 530 return BP_Messages_Thread::mark_as_unread( $thread_id ); 531 531 } 532 532 … … 545 545 function messages_get_unread_count( $user_id = false ) { 546 546 global $bp; 547 548 if ( !$user_id ) 547 548 if ( !$user_id ) 549 549 $user_id = $bp->loggedin_user->id; 550 550 551 551 return BP_Messages_Thread::get_inbox_count( $user_id ); 552 552 }
Note: See TracChangeset
for help on using the changeset viewer.