item_capacity = max( 1, intval( $item_limit ) ); mbstring_binary_safe_encoding(); // So we can safely use strlen(). $this->byte_capacity = max( 1, intval( $byte_limit ) ) - strlen( $header ) - strlen( $footer ); reset_mbstring_encoding(); $this->footer_text = $footer; $this->buffer = $header; $this->is_full_flag = false; $this->is_empty_flag = true; $this->timestamp = $time; return; } /** * Append an item to the buffer, if there is room for it, * and set is_empty_flag to false. If there is no room, * we set is_full_flag to true. If $item is null, * don't do anything and report success. * * @since 4.8.0 * * @param string $item The item to be added. * * @return bool True if the append succeeded, False if not. */ public function try_to_add_item( $item ) { if ( is_null( $item ) ) { return true; } else { mbstring_binary_safe_encoding(); // So we can safely use strlen(). $item_size = strlen( $item ); // Size in bytes. reset_mbstring_encoding(); if ( 0 >= $this->item_capacity || 0 > $this->byte_capacity - $item_size ) { $this->is_full_flag = true; return false; } else { $this->is_empty_flag = false; $this->item_capacity -= 1; $this->byte_capacity -= $item_size; $this->buffer .= $item; return true; } } } /** * Retrieve the contents of the buffer. * * @since 4.8.0 * * @return string The contents of the buffer (with the footer included). */ public function contents() { return $this->buffer . $this->footer_text; } /** * Detect whether the buffer is full. * * @since 4.8.0 * * @return bool True if the buffer is full, false otherwise. */ public function is_full() { return $this->is_full_flag; } /** * Detect whether the buffer is empty. * * @since 4.8.0 * * @return bool True if the buffer is empty, false otherwise. */ public function is_empty() { return $this->is_empty_flag; } /** * Update the timestamp of the buffer. * * @since 4.8.0 * * @param string $new_time A datetime string in 'YYYY-MM-DD hh:mm:ss' format. */ public function view_time( $new_time ) { $this->timestamp = max( $this->timestamp, $new_time ); return; } /** * Retrieve the timestamp of the buffer. * * @since 4.8.0 * * @return string A datetime string in 'YYYY-MM-DD hh:mm:ss' format. */ public function last_modified() { return $this->timestamp; } /** * Render an associative array as an XML string. This is needed because * SimpleXMLElement only handles valid XML, but we sometimes want to * pass around (possibly invalid) fragments. Note that 'null' values make * a tag self-closing; this is only sometimes correct (depending on the * version of HTML/XML); see the list of 'void tags'. * * Example: * * array( * 'html' => array( | * 'head' => array( |
* 'title' => 'Woo!', |it's all up ons
* 'br' => null, |