[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Messages Thread Template Class. 4 * 5 * @package BuddyPress 6 * @subpackage MessagesClasses 7 * @since 1.5.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Message Thread Template Class 15 */ 16 class BP_Messages_Thread_Template { 17 18 /** 19 * The loop iterator. 20 * 21 * @var int 22 */ 23 public $current_message = -1; 24 25 /** 26 * Number of messages returned by the paged query. 27 * 28 * @var int 29 */ 30 public $message_count = 0; 31 32 /** 33 * The message object currently being iterated on. 34 * 35 * @var object 36 */ 37 public $message; 38 39 /** 40 * Thread that the current messages belong to. 41 * 42 * @var BP_Messages_Thread 43 */ 44 public $thread; 45 46 /** 47 * A flag for whether the loop is currently being iterated. 48 * 49 * @var bool 50 */ 51 public $in_the_loop = false; 52 53 /** 54 * The page number being requested. 55 * 56 * @var int 57 */ 58 public $pag_page = 1; 59 60 /** 61 * The number of items being requested per page. 62 * 63 * @var int 64 */ 65 public $pag_num = 10; 66 67 /** 68 * An HTML string containing pagination links. 69 * 70 * @var string 71 */ 72 public $pag_links = ''; 73 74 /** 75 * The total number of messages matching the query. 76 * 77 * @var int 78 */ 79 public $total_message_count = 0; 80 81 /** 82 * Constructor method. 83 * 84 * @see BP_Messages_Thread::populate() for full parameter info. 85 * 86 * @param int $thread_id ID of the message thread to display. 87 * @param string $order Optional. Order to show the thread's messages in. 88 * Default: 'ASC'. 89 * @param array $args Array of arguments for the query. 90 */ 91 public function __construct( $thread_id = 0, $order = 'ASC', $args = array() ) { 92 $this->thread = new BP_Messages_Thread( $thread_id, $order, $args ); 93 $this->message_count = count( $this->thread->messages ); 94 } 95 96 /** 97 * Whether there are messages available in the loop. 98 * 99 * @see bp_thread_has_messages() 100 * 101 * @return bool True if there are items in the loop, otherwise false. 102 */ 103 public function has_messages() { 104 return ( ! empty( $this->message_count ) ); 105 } 106 107 /** 108 * Set up the next message and iterate index. 109 * 110 * @return BP_Messages_Message The next message to iterate over. 111 */ 112 public function next_message() { 113 $this->current_message++; 114 $this->message = $this->thread->messages[ $this->current_message ]; 115 116 return $this->message; 117 } 118 119 /** 120 * Rewind the messages and reset message index. 121 */ 122 public function rewind_messages() { 123 $this->current_message = -1; 124 if ( $this->message_count > 0 ) { 125 $this->message = $this->thread->messages[0]; 126 } 127 } 128 129 /** 130 * Whether there are messages left in the loop to iterate over. 131 * 132 * This method is used by {@link bp_thread_messages()} as part of the 133 * while loop that controls iteration inside the messages loop, eg: 134 * while ( bp_thread_messages() ) { ... 135 * 136 * @see bp_thread_messages() 137 * 138 * @return bool True if there are more messages to show, otherwise false. 139 */ 140 public function messages() { 141 if ( ( $this->current_message + 1 ) < $this->message_count ) { 142 return true; 143 } elseif ( ( $this->current_message + 1 ) === $this->message_count ) { 144 145 /** 146 * Fires when at the end of messages to iterate over. 147 * 148 * @since 1.1.0 149 */ 150 do_action( 'thread_loop_end' ); 151 // Do some cleaning up after the loop. 152 $this->rewind_messages(); 153 } 154 155 $this->in_the_loop = false; 156 return false; 157 } 158 159 /** 160 * Set up the current message inside the loop. 161 * 162 * Used by {@link bp_thread_the_message()} to set up the current 163 * message data while looping, so that template tags used during 164 * that iteration make reference to the current message. 165 * 166 * @see bp_thread_the_message() 167 */ 168 public function the_message() { 169 $this->in_the_loop = true; 170 $this->message = $this->next_message(); 171 172 // Loop has just started. 173 if ( 0 === $this->current_message ) { 174 175 /** 176 * Fires if at the start of the message loop. 177 * 178 * @since 1.1.0 179 */ 180 do_action( 'thread_loop_start' ); 181 } 182 } 183 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |