is_full_flag = false; $this->timestamp = $time; $this->finder = new Jetpack_Sitemap_Finder(); $this->doc = new DOMDocument( '1.0', 'UTF-8' ); $this->item_capacity = max( 1, intval( $item_limit ) ); $this->byte_capacity = max( 1, intval( $byte_limit ) ) - strlen( $this->doc->saveXML() ); } /** * Returns a DOM element that contains all sitemap elements. * * @access protected * @since 5.3.0 * @return DOMElement $root */ abstract protected function get_root_element(); /** * 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 * @deprecated 5.3.0 Use Jetpack_Sitemap_Buffer::append. * * @param string $item The item to be added. */ public function try_to_add_item( $item ) { _deprecated_function( 'Jetpack_Sitemap_Buffer::try_to_add_item', '5.3.0', 'Jetpack_Sitemap_Buffer::append' ); $this->append( $item ); } /** * 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 5.3.0 * * @param array $array The item to be added. * * @return bool True if the append succeeded, False if not. */ public function append( $array ) { if ( is_null( $array ) ) { return true; } if ( $this->is_full_flag ) { return false; } if ( 0 >= $this->item_capacity || 0 >= $this->byte_capacity ) { $this->is_full_flag = true; return false; } else { $this->item_capacity -= 1; $added_element = $this->array_to_xml_string( $array, $this->get_root_element(), $this->doc ); $this->byte_capacity -= strlen( $this->doc->saveXML( $added_element ) ); 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() { if ( $this->is_empty() ) { // The sitemap should have at least the root element added to the DOM. $this->get_root_element(); } return $this->doc->saveXML(); } /** * Retrieve the document object. * * @since 5.3.0 * @return DOMDocument $doc */ public function get_document() { return $this->doc; } /** * 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 ( ! isset( $this->root ) || ! $this->root->hasChildNodes() ); } /** * 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 ); } /** * 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, |