Changeset 9947
- Timestamp:
- 06/15/2015 11:54:42 PM (9 years ago)
- Location:
- trunk/src/bp-messages
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/bp-messages-actions.php
r9862 r9947 14 14 // Exit if accessed directly 15 15 defined( 'ABSPATH' ) || exit; 16 17 /** 18 * Handle creating of private messages or sitewide notices 19 * 20 * @since BuddyPress (2.4.0) 21 * 22 * @return boolean 23 */ 24 function bp_messages_action_create_message() { 25 26 // Bail if not posting to the compose message screen 27 if ( ! bp_is_post_request() || ! bp_is_messages_component() || ! bp_is_current_action( 'compose' ) ) { 28 return false; 29 } 30 31 // Check the nonce 32 check_admin_referer( 'messages_send_message' ); 33 34 // Define local variables 35 $redirect_to = ''; 36 $feedback = ''; 37 $success = false; 38 39 // Missing subject or content 40 if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) { 41 $success = false; 42 $feedback = __( 'Message was not sent. Check the contents and try again.', 'buddypress' ); 43 44 // Subject and content present 45 } else { 46 47 // Setup the link to the logged-in user's messages 48 $member_messages = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 49 50 // Site-wide notice 51 if ( isset( $_POST['send-notice'] ) ) { 52 53 // Attempt to save the notice and redirect to notices 54 if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) { 55 $success = true; 56 $feedback = __( 'Notice successfully created.', 'buddypress' ); 57 $redirect_to = trailingslashit( $member_messages . 'notices' ); 58 59 // Notice could not be sent 60 } else { 61 $success = false; 62 $feedback = __( 'Notice was not created. Please try again.', 'buddypress' ); 63 } 64 65 // Private conversation 66 } else { 67 68 // Filter recipients into the format we need - array( 'username/userid', 'username/userid' ) 69 $autocomplete_recipients = (array) explode( ',', $_POST['send-to-input'] ); 70 $typed_recipients = (array) explode( ' ', $_POST['send_to_usernames'] ); 71 $recipients = array_merge( $autocomplete_recipients, $typed_recipients ); 72 73 /** 74 * Filters the array of recipients to receive the composed message. 75 * 76 * @since BuddyPress (1.2.10) 77 * 78 * @param array $recipients Array of recipients to receive message. 79 */ 80 $recipients = apply_filters( 'bp_messages_recipients', $recipients ); 81 82 // Attempt to send the message 83 $thread_id = messages_new_message( array( 84 'recipients' => $recipients, 85 'subject' => $_POST['subject'], 86 'content' => $_POST['content'] 87 ) ); 88 89 // Send the message and redirect to it 90 if ( ! empty( $thread_id ) ) { 91 $success = true; 92 $feedback = __( 'Message successfully sent.', 'buddypress' ); 93 $view = trailingslashit( $member_messages . 'view' ); 94 $redirect_to = trailingslashit( $view . $thread_id ); 95 96 // Message could not be sent 97 } else { 98 $success = false; 99 $feedback = __( 'Message was not sent. Please try again.', 'buddypress' ); 100 } 101 } 102 } 103 104 // Feedback 105 if ( ! empty( $feedback ) ) { 106 107 // Determine message type 108 $type = ( true === $success ) 109 ? 'success' 110 : 'error'; 111 112 // Add feedback message 113 bp_core_add_message( $feedback, $type ); 114 } 115 116 // Maybe redirect 117 if ( ! empty( $redirect_to ) ) { 118 bp_core_redirect( $redirect_to ); 119 } 120 } 121 add_action( 'bp_actions', 'bp_messages_action_create_message' ); 122 123 /** 124 * Handle editing of sitewide notices 125 * 126 * @since BuddyPress (2.4.0) 127 * 128 * @global int $notice_id 129 * 130 * @return boolean 131 */ 132 function bp_messages_action_edit_notice() { 133 global $notice_id; 134 135 // Bail if not viewing a single notice URL 136 if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) || ! bp_action_variable( 1 ) ) { 137 return false; 138 } 139 140 // Get action variables 141 $action = bp_action_variable( 0 ); // deactivate|activate|delete 142 $notice_id = bp_action_variable( 1 ); // 1|2|3|etc... 143 144 // Bail if notice ID is not numeric 145 if ( ! is_numeric( $notice_id ) ) { 146 return; 147 } 148 149 // Define local variables 150 $redirect_to = ''; 151 $feedback = ''; 152 $success = false; 153 154 // Get the notice from database 155 $notice = new BP_Messages_Notice( $notice_id ); 156 157 // Take action 158 switch ( $action ) { 159 160 // Deactivate 161 case 'deactivate' : 162 $success = $notice->deactivate(); 163 $feedback = true === $success 164 ? __( 'Notice deactivated successfully.', 'buddypress' ) 165 : __( 'There was a problem deactivating that notice.', 'buddypress' ); 166 break; 167 168 // Activate 169 case 'activate' : 170 $success = $notice->activate(); 171 $feedback = true === $success 172 ? __( 'Notice activated successfully.', 'buddypress' ) 173 : __( 'There was a problem activating that notice.', 'buddypress' ); 174 break; 175 176 // Delete 177 case 'delete' : 178 $success = $notice->delete(); 179 $feedback = true === $success 180 ? __( 'Notice deleted successfully.', 'buddypress' ) 181 : __( 'There was a problem deleting that notice.', 'buddypress' ); 182 break; 183 } 184 185 // Feedback 186 if ( ! empty( $feedback ) ) { 187 188 // Determine message type 189 $type = ( true === $success ) 190 ? 'success' 191 : 'error'; 192 193 // Add feedback message 194 bp_core_add_message( $feedback, $type ); 195 } 196 197 // Redirect 198 $member_notices = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 199 $redirect_to = trailingslashit( $member_notices . 'notices' ); 200 201 bp_core_redirect( $redirect_to ); 202 } 203 add_action( 'bp_actions', 'bp_messages_action_edit_notice' ); 16 204 17 205 /** -
trunk/src/bp-messages/bp-messages-screens.php
r9946 r9947 17 17 /** 18 18 * Load the Messages > Inbox screen. 19 * 20 * @since BuddyPress (1.0.0) 19 21 */ 20 22 function messages_screen_inbox() { 23 21 24 if ( bp_action_variables() ) { 22 25 bp_do_404(); … … 43 46 /** 44 47 * Load the Messages > Sent screen. 48 * 49 * @since BuddyPress (1.0.0) 45 50 */ 46 51 function messages_screen_sentbox() { 52 47 53 if ( bp_action_variables() ) { 48 54 bp_do_404(); … … 69 75 /** 70 76 * Load the Messages > Compose screen. 77 * 78 * @since BuddyPress (1.0.0) 71 79 */ 72 80 function messages_screen_compose() { … … 80 88 messages_remove_callback_values(); 81 89 82 // Check if the message form has been submitted83 if ( isset( $_POST['send'] ) ) {84 85 // Check the nonce86 check_admin_referer( 'messages_send_message' );87 88 // Check we have what we need89 if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) {90 bp_core_add_message( __( 'There was an error sending that message. Please try again.', 'buddypress' ), 'error' );91 } else {92 // If this is a notice, send it93 if ( isset( $_POST['send-notice'] ) ) {94 if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) {95 bp_core_add_message( __( 'Notice sent successfully!', 'buddypress' ) );96 bp_core_redirect( bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox/' );97 } else {98 bp_core_add_message( __( 'There was an error sending that notice. Please try again.', 'buddypress' ), 'error' );99 }100 } else {101 // Filter recipients into the format we need - array( 'username/userid', 'username/userid' )102 $autocomplete_recipients = explode( ',', $_POST['send-to-input'] );103 $typed_recipients = explode( ' ', $_POST['send_to_usernames'] );104 $recipients = array_merge( (array) $autocomplete_recipients, (array) $typed_recipients );105 106 /**107 * Filters the array of recipients to receive the composed message.108 *109 * @since BuddyPress (1.2.10)110 *111 * @param array $recipients Array of recipients to receive message.112 */113 $recipients = apply_filters( 'bp_messages_recipients', $recipients );114 $thread_id = messages_new_message( array(115 'recipients' => $recipients,116 'subject' => $_POST['subject'],117 'content' => $_POST['content']118 ) );119 120 // Send the message121 if ( ! empty( $thread_id ) ) {122 bp_core_add_message( __( 'Message sent successfully!', 'buddypress' ) );123 bp_core_redirect( bp_loggedin_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/' );124 } else {125 bp_core_add_message( __( 'There was an error sending that message. Please try again.', 'buddypress' ), 'error' );126 }127 }128 }129 }130 131 90 /** 132 91 * Fires right before the loading of the Messages compose screen template file. … … 149 108 * Load an individual conversation screen. 150 109 * 110 * @since BuddyPress (1.0.0) 111 * 151 112 * @return bool|null False on failure. 152 113 */ … … 154 115 155 116 // Bail if not viewing a single message 156 if ( ! bp_is_messages_component() || !bp_is_current_action( 'view' ) ) {117 if ( ! bp_is_messages_component() || ! bp_is_current_action( 'view' ) ) { 157 118 return false; 158 119 } … … 160 121 $thread_id = (int) bp_action_variable( 0 ); 161 122 162 if ( empty( $thread_id ) || ! messages_is_valid_thread( $thread_id ) || ( !messages_check_thread_access( $thread_id ) && !bp_current_user_can( 'bp_moderate' ) ) ) {123 if ( empty( $thread_id ) || ! messages_is_valid_thread( $thread_id ) || ( ! messages_check_thread_access( $thread_id ) && ! bp_current_user_can( 'bp_moderate' ) ) ) { 163 124 bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() ) ); 164 125 } … … 191 152 * Load the Messages > Notices screen. 192 153 * 154 * @since BuddyPress (1.0.0) 155 * 193 156 * @return false|null False on failure. 194 157 */ 195 158 function messages_screen_notices() { 196 global $notice_id;197 198 $notice_id = (int) bp_action_variable( 1 );199 200 if ( !empty( $notice_id ) && is_numeric( $notice_id ) ) {201 $notice = new BP_Messages_Notice( $notice_id );202 203 if ( bp_is_action_variable( 'deactivate', 0 ) ) {204 if ( !$notice->deactivate() ) {205 bp_core_add_message( __('There was a problem deactivating that notice.', 'buddypress'), 'error' );206 } else {207 bp_core_add_message( __('Notice deactivated.', 'buddypress') );208 }209 } elseif ( bp_is_action_variable( 'activate', 0 ) ) {210 if ( !$notice->activate() ) {211 bp_core_add_message( __('There was a problem activating that notice.', 'buddypress'), 'error' );212 } else {213 bp_core_add_message( __('Notice activated.', 'buddypress') );214 }215 } elseif ( bp_is_action_variable( 'delete' ) ) {216 if ( !$notice->delete() ) {217 bp_core_add_message( __('There was a problem deleting that notice.', 'buddypress'), 'buddypress' );218 } else {219 bp_core_add_message( __('Notice deleted.', 'buddypress') );220 }221 }222 bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices' ) );223 }224 159 225 160 if ( bp_action_variables() ) { … … 247 182 /** 248 183 * Render the markup for the Messages section of Settings > Notifications. 184 * 185 * @since BuddyPress (1.0.0) 249 186 */ 250 187 function messages_screen_notification_settings() { 188 251 189 if ( bp_action_variables() ) { 252 190 bp_do_404();
Note: See TracChangeset
for help on using the changeset viewer.