コード例 #1
0
	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
			) );
		}
	}
コード例 #2
0
 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));
     }
 }
コード例 #3
0
 /**
  * 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));
     }
 }