/** * Render the widget. * * @see WP_Widget::widget() for a description of parameters. * * @param array $args See {@WP_Widget::widget()}. * @param array $args See {@WP_Widget::widget()}. */ public function widget($args, $instance) { if (!is_user_logged_in()) { return; } // Don't display the widget if there are no Notices to show $notices = BP_Messages_Notice::get_active(); if (empty($notices)) { return; } extract($args); $title = !empty($instance['title']) ? $instance['title'] : ''; $title = apply_filters('widget_title', $title, $instance); echo $before_widget; echo $before_title . $title . $after_title; ?> <div class="bp-site-wide-message"> <?php bp_message_get_notices(); ?> </div> <?php echo $after_widget; }
function bp_messages_box_template( $user_id, $box, $per_page, $max, $type ) { $this->pag_page = isset( $_GET['mpage'] ) ? intval( $_GET['mpage'] ) : 1; $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page; $this->user_id = $user_id; $this->box = $box; $this->type = $type; if ( 'notices' == $this->box ) { $this->threads = BP_Messages_Notice::get_notices(); } else { $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page ); $this->threads = $threads['threads']; $this->total_thread_count = $threads['total']; } if ( !$this->threads ) { $this->thread_count = 0; $this->total_thread_count = 0; } else { $total_notice_count = BP_Messages_Notice::get_total_notice_count(); if ( !$max || $max >= (int)$total_notice_count ) { if ( 'notices' == $this->box ) { $this->total_thread_count = (int)$total_notice_count; } } else { $this->total_thread_count = (int)$max; } if ( $max ) { if ( $max >= count($this->threads) ) { $this->thread_count = count($this->threads); } else { $this->thread_count = (int)$max; } } else { $this->thread_count = count($this->threads); } } if ( (int)$this->total_thread_count && (int)$this->pag_num ) { $this->pag_links = paginate_links( array( 'base' => add_query_arg( 'mpage', '%#%' ), 'format' => '', 'total' => ceil( (int)$this->total_thread_count / (int)$this->pag_num ), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1 ) ); } }
function messages_screen_notices() { global $notice_id; if (!is_super_admin()) { return false; } $notice_id = (int) bp_action_variable(1); if (!empty($notice_id) && is_numeric($notice_id)) { $notice = new BP_Messages_Notice($notice_id); if (bp_is_action_variable('deactivate', 0)) { if (!$notice->deactivate()) { bp_core_add_message(__('There was a problem deactivating that notice.', 'buddypress'), 'error'); } else { bp_core_add_message(__('Notice deactivated.', 'buddypress')); } } else { if (bp_is_action_variable('activate', 0)) { if (!$notice->activate()) { bp_core_add_message(__('There was a problem activating that notice.', 'buddypress'), 'error'); } else { bp_core_add_message(__('Notice activated.', 'buddypress')); } } else { if (bp_is_action_variable('delete')) { if (!$notice->delete()) { bp_core_add_message(__('There was a problem deleting that notice.', 'buddypress'), 'buddypress'); } else { bp_core_add_message(__('Notice deleted.', 'buddypress')); } } } } bp_core_redirect(bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices'); } if (bp_action_variables()) { bp_do_404(); return; } do_action('messages_screen_notices'); bp_core_load_template(apply_filters('messages_template_notices', 'members/single/home')); }
function __construct($user_id, $box, $per_page, $max, $type, $search_terms, $page_arg = 'mpage') { $this->pag_page = isset($_GET[$page_arg]) ? intval($_GET[$page_arg]) : 1; $this->pag_num = isset($_GET['num']) ? intval($_GET['num']) : $per_page; $this->user_id = $user_id; $this->box = $box; $this->type = $type; $this->search_terms = $search_terms; if ('notices' == $this->box) { $this->threads = BP_Messages_Notice::get_notices(array('pag_num' => $this->pag_num, 'pag_page' => $this->pag_page)); } else { $threads = BP_Messages_Thread::get_current_threads_for_user($this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page, $this->search_terms); $this->threads = $threads['threads']; $this->total_thread_count = $threads['total']; } if (!$this->threads) { $this->thread_count = 0; $this->total_thread_count = 0; } else { $total_notice_count = BP_Messages_Notice::get_total_notice_count(); if (!$max || $max >= (int) $total_notice_count) { if ('notices' == $this->box) { $this->total_thread_count = (int) $total_notice_count; } } else { $this->total_thread_count = (int) $max; } if ($max) { if ($max >= count($this->threads)) { $this->thread_count = count($this->threads); } else { $this->thread_count = (int) $max; } } else { $this->thread_count = count($this->threads); } } if ((int) $this->total_thread_count && (int) $this->pag_num) { $this->pag_links = paginate_links(array('base' => add_query_arg($page_arg, '%#%'), 'format' => '', 'total' => ceil((int) $this->total_thread_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Message pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Message pagination next text', 'buddypress'), 'mid_size' => 1)); } }
/** * Render the widget. * * @see WP_Widget::widget() for a description of parameters. * * @param array $args See {@WP_Widget::widget()}. * @param array $instance See {@WP_Widget::widget()}. */ public function widget($args, $instance) { if (!is_user_logged_in()) { return; } // Don't display the widget if there are no Notices to show $notices = BP_Messages_Notice::get_active(); if (empty($notices)) { return; } extract($args); $title = !empty($instance['title']) ? $instance['title'] : ''; /** * Filters the title of the Messages widget. * * @since 1.9.0 * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. * * @param string $title The widget title. * @param array $instance The settings for the particular instance of the widget. * @param string $id_base Root ID for all widgets of this type. */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); echo $before_widget; echo $before_title . $title . $after_title; ?> <div class="bp-site-wide-message"> <?php bp_message_get_notices(); ?> </div> <?php echo $after_widget; }
/** * @group cache */ public function test_get_active_notices() { // send notice $subject = 'Test notice'; $message = 'This is a notice'; messages_send_notice($subject, $message); // now get the active notice and assert $notice = BP_Messages_Notice::get_active(); $this->assertEquals($subject, $notice->subject); $this->assertEquals($message, $notice->message); // deactivate notice and make sure cache is invalidated $notice->deactivate(); $this->assertFalse(wp_cache_get('active_notice', 'bp_messages')); // create a new notice $subject2 = 'Another notice'; $message2 = 'Say what?'; messages_send_notice($subject2, $message2); // now get the new active notice BP_Messages_Notice::get_active(); // grab the cache and make sure it equals our new notice $cache = wp_cache_get('active_notice', 'bp_messages'); $this->assertEquals($subject2, $cache->subject); $this->assertEquals($message2, $cache->message); }
function messages_send_notice( $subject, $message ) { if ( !is_super_admin() || empty( $subject ) || empty( $message ) ) { return false; } else { // Has access to send notices, lets do it. $notice = new BP_Messages_Notice; $notice->subject = $subject; $notice->message = $message; $notice->date_sent = bp_core_current_time(); $notice->is_active = 1; $notice->save(); // send it. do_action( 'messages_send_notice', $subject, $message ); return true; } }
/** * Generate markup for currently active notices. */ function bp_message_get_notices() { $notice = BP_Messages_Notice::get_active(); if (empty($notice)) { return false; } $closed_notices = bp_get_user_meta(bp_loggedin_user_id(), 'closed_notices', true); if (empty($closed_notices)) { $closed_notices = array(); } if (is_array($closed_notices)) { if (!in_array($notice->id, $closed_notices) && $notice->id) { ?> <div id="message" class="info notice" rel="n-<?php echo esc_attr($notice->id); ?> "> <p> <strong><?php echo stripslashes(wp_filter_kses($notice->subject)); ?> </strong><br /> <?php echo stripslashes(wp_filter_kses($notice->message)); ?> <a href="#" id="close-notice"><?php _e('Close', 'buddypress'); ?> </a> </p> </div> <?php } } }
/** * Constructor method. * * @param array $args { * Array of arguments. See bp_has_message_threads() for full description. * } */ public function __construct($args = array()) { // Backward compatibility with old method of passing arguments if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '2.2.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__)); $old_args_keys = array(0 => 'user_id', 1 => 'box', 2 => 'per_page', 3 => 'max', 4 => 'type', 5 => 'search_terms', 6 => 'page_arg'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $r = wp_parse_args($args, array('page' => 1, 'per_page' => 10, 'page_arg' => 'mpage', 'box' => 'inbox', 'type' => 'all', 'user_id' => bp_loggedin_user_id(), 'max' => false, 'search_terms' => '', 'meta_query' => array())); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); $this->user_id = $r['user_id']; $this->box = $r['box']; $this->type = $r['type']; $this->search_terms = $r['search_terms']; if ('notices' === $this->box) { $this->threads = BP_Messages_Notice::get_notices(array('pag_num' => $this->pag_num, 'pag_page' => $this->pag_page)); } else { $threads = BP_Messages_Thread::get_current_threads_for_user(array('user_id' => $this->user_id, 'box' => $this->box, 'type' => $this->type, 'limit' => $this->pag_num, 'page' => $this->pag_page, 'search_terms' => $this->search_terms, 'meta_query' => $r['meta_query'])); $this->threads = $threads['threads']; $this->total_thread_count = $threads['total']; } if (!$this->threads) { $this->thread_count = 0; $this->total_thread_count = 0; } else { $total_notice_count = BP_Messages_Notice::get_total_notice_count(); if (empty($r['max']) || (int) $r['max'] >= (int) $total_notice_count) { if ('notices' === $this->box) { $this->total_thread_count = (int) $total_notice_count; } } else { $this->total_thread_count = (int) $r['max']; } if (!empty($r['max'])) { if ((int) $r['max'] >= count($this->threads)) { $this->thread_count = count($this->threads); } else { $this->thread_count = (int) $r['max']; } } else { $this->thread_count = count($this->threads); } } if ((int) $this->total_thread_count && (int) $this->pag_num) { $pag_args = array($r['page_arg'] => '%#%'); if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) { $base = remove_query_arg('s', wp_get_referer()); } else { $base = ''; } $add_args = array(); if (!empty($this->search_terms)) { $add_args['s'] = $this->search_terms; } $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), 'format' => '', 'total' => ceil((int) $this->total_thread_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Message pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Message pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => $add_args)); } }
function messages_send_notice($subject, $message) { if (!bp_current_user_can('bp_moderate') || empty($subject) || empty($message)) { return false; // Has access to send notices, lets do it. } else { $notice = new BP_Messages_Notice(); $notice->subject = $subject; $notice->message = $message; $notice->date_sent = bp_core_current_time(); $notice->is_active = 1; $notice->save(); // send it. do_action_ref_array('messages_send_notice', array($subject, $message)); return true; } }
function firmasite_bp_message_get_notices() { global $userdata; $notice = BP_Messages_Notice::get_active(); if (empty($notice)) { return false; } $closed_notices = bp_get_user_meta($userdata->ID, 'closed_notices', true); if (!$closed_notices) { $closed_notices = array(); } if (is_array($closed_notices)) { if (!in_array($notice->id, $closed_notices) && $notice->id) { ?> <div id="message-<?php echo $notice->id; ?> " class="info notice modal fade" rel="n-<?php echo $notice->id; ?> " tabindex="-1" role="dialog" aria-hidden="false"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h3 class="modal-title"><?php echo stripslashes(wp_filter_kses($notice->subject)); ?> </h3> </div> <div class="modal-body"> <p><?php echo stripslashes(wp_filter_kses($notice->message)); ?> </p> </div> <div class="modal-footer"> <a href="#" id="close-notice" class="btn btn-primary" data-dismiss="modal" aria-hidden="true"><?php _e('Close', 'firmasite'); ?> </a> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div> <script> jQuery(document).ready(function() { jQuery('#message-<?php echo $notice->id; ?> ').modal('show'); jQuery("#message-<?php echo $notice->id; ?> #close-notice").click(function(){ jQuery('#message-<?php echo $notice->id; ?> ').modal('hide'); }); }); </script> <?php } } }
/** * Send a notice. * * @param string $subject Subject of the notice. * @param string $message Content of the notice. * @return bool True on success, false on failure. */ function messages_send_notice($subject, $message) { if (!bp_current_user_can('bp_moderate') || empty($subject) || empty($message)) { return false; // Has access to send notices, lets do it. } else { $notice = new BP_Messages_Notice(); $notice->subject = $subject; $notice->message = $message; $notice->date_sent = bp_core_current_time(); $notice->is_active = 1; $notice->save(); // Send it. /** * Fires after a notice has been successfully sent. * * @since 1.0.0 * * @param string $subject Subject of the notice. * @param string $message Content of the notice. */ do_action_ref_array('messages_send_notice', array($subject, $message)); return true; } }
/** * Load the Messages > Notices screen. * * @return false|null False on failure. */ function messages_screen_notices() { global $notice_id; if (!bp_current_user_can('bp_moderate')) { return false; } $notice_id = (int) bp_action_variable(1); if (!empty($notice_id) && is_numeric($notice_id)) { $notice = new BP_Messages_Notice($notice_id); if (bp_is_action_variable('deactivate', 0)) { if (!$notice->deactivate()) { bp_core_add_message(__('There was a problem deactivating that notice.', 'buddypress'), 'error'); } else { bp_core_add_message(__('Notice deactivated.', 'buddypress')); } } elseif (bp_is_action_variable('activate', 0)) { if (!$notice->activate()) { bp_core_add_message(__('There was a problem activating that notice.', 'buddypress'), 'error'); } else { bp_core_add_message(__('Notice activated.', 'buddypress')); } } elseif (bp_is_action_variable('delete')) { if (!$notice->delete()) { bp_core_add_message(__('There was a problem deleting that notice.', 'buddypress'), 'buddypress'); } else { bp_core_add_message(__('Notice deleted.', 'buddypress')); } } bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices')); } if (bp_action_variables()) { bp_do_404(); return; } /** * Fires right before the loading of the Messages notices screen template file. * * @since BuddyPress (1.0.0) */ do_action('messages_screen_notices'); /** * Filters the template to load for the Messages notices screen. * * @since BuddyPress (1.0.0) * * @param string $template Path to the messages template to load. */ bp_core_load_template(apply_filters('messages_template_notices', 'members/single/home')); }
/** * Handle editing of sitewide notices * * @since BuddyPress (2.4.0) This function was split from messages_screen_notices(). See #6505. * * @global int $notice_id * * @return boolean */ function bp_messages_action_edit_notice() { global $notice_id; // Bail if not viewing a single notice URL if (!bp_is_messages_component() || !bp_is_current_action('notices') || !bp_action_variable(1)) { return false; } // Get action variables $action = bp_action_variable(0); // deactivate|activate|delete $notice_id = bp_action_variable(1); // 1|2|3|etc... // Bail if notice ID is not numeric if (!is_numeric($notice_id)) { return; } // Define local variables $redirect_to = ''; $feedback = ''; $success = false; // Get the notice from database $notice = new BP_Messages_Notice($notice_id); // Take action switch ($action) { // Deactivate case 'deactivate': $success = $notice->deactivate(); $feedback = true === $success ? __('Notice deactivated successfully.', 'buddypress') : __('There was a problem deactivating that notice.', 'buddypress'); break; // Activate // Activate case 'activate': $success = $notice->activate(); $feedback = true === $success ? __('Notice activated successfully.', 'buddypress') : __('There was a problem activating that notice.', 'buddypress'); break; // Delete // Delete case 'delete': $success = $notice->delete(); $feedback = true === $success ? __('Notice deleted successfully.', 'buddypress') : __('There was a problem deleting that notice.', 'buddypress'); break; } // Feedback if (!empty($feedback)) { // Determine message type $type = true === $success ? 'success' : 'error'; // Add feedback message bp_core_add_message($feedback, $type); } // Redirect $member_notices = trailingslashit(bp_loggedin_user_domain() . bp_get_messages_slug()); $redirect_to = trailingslashit($member_notices . 'notices'); bp_core_redirect($redirect_to); }
/** * Customize bp_message_get_notices() function * * Instead of down in the sidebar, the sitewide notice display is moved to just above the primary navigation. * * @since 1.6 */ function frisco_bp_message_get_notices() { global $userdata; $notice = BP_Messages_Notice::get_active(); if (empty($notice)) { return false; } $closed_notices = bp_get_user_meta($userdata->ID, 'closed_notices', true); if (!$closed_notices) { $closed_notices = array(); } if (is_array($closed_notices)) { if (!in_array($notice->id, $closed_notices) && $notice->id) { ?> <div id="message" class="info notice frisco_notice" rel="n-<?php echo $notice->id; ?> "> <p> <strong><?php echo stripslashes(wp_filter_kses($notice->subject)); ?> </strong> <?php echo stripslashes(wp_filter_kses($notice->message)); ?> <a href="#" id="close-notice"><?php _e('x', 'friscotheme'); ?> </a> </p> </div> <?php } } }