You appear to be a bot. Output may be restricted
Description
Build and store a single page sitemap index. Return false if no index is built.
Side effect: Create/update a sitemap index row.
Usage
$bool|array = Jetpack_Sitemap_Builder::build_one_sitemap_index( $number, $from_id, $datetime, $index_type );
Parameters
- $number
- ( int ) required – The number of the current sitemap index.
- $from_id
- ( int ) required – The greatest lower bound of the IDs of the sitemaps to be included.
- $datetime
- ( string ) required – Datetime of previous sitemap in 'YYYY-MM-DD hh:mm:ss' format.
- $index_type
- ( string ) required – Sitemap index type.
- $last_id
- ( int ) required – The ID of the last item to be successfully added to the buffer.
- $any_left
- ( bool ) required – 'true' if there are items which haven't been saved to a sitemap, 'false' otherwise.
- $last_modified
- ( string ) required – The most recent timestamp to appear on the sitemap. }
Returns
bool|array @args {
Source
File name: jetpack/modules/sitemaps/sitemap-builder.php
Lines:
1 to 91 of 91
private function build_one_sitemap_index( $number, $from_id, $datetime, $index_type ) { $last_sitemap_id = $from_id; $any_sitemaps_left = true; // Check the datetime format. $datetime = jp_sitemap_datetime( $datetime ); $sitemap_type = jp_sitemap_child_type_of( $index_type ); if ( $this->logger ) { $index_debug_name = jp_sitemap_filename( $index_type, $number ); $this->logger->report( "-- Building $index_debug_name" ); } $buffer = new Jetpack_Sitemap_Buffer_Master( JP_SITEMAP_MAX_ITEMS, JP_SITEMAP_MAX_BYTES, $datetime ); // Add pointer to the previous sitemap index (unless we're at the first one). if ( 1 !== $number ) { $i = $number - 1; $prev_index_url = $this->finder->construct_sitemap_url( jp_sitemap_filename( $index_type, $i ) ); $item_array = array( 'sitemap' => array( 'loc' => $prev_index_url, 'lastmod' => $datetime, ), ); $buffer->append( $item_array ); } // Add as many items to the buffer as possible. while ( false === $buffer->is_full() ) { // Retrieve a batch of posts (in order). $posts = $this->librarian->query_sitemaps_after_id( $sitemap_type, $last_sitemap_id, JP_SITEMAP_BATCH_SIZE ); // If there were no posts to get, make a note. if ( null == $posts ) { // WPCS: loose comparison ok. $any_sitemaps_left = false; break; } // Otherwise, loop through each post in the batch. foreach ( $posts as $post ) { // Generate the sitemap XML for the post. $current_item = $this->sitemap_row_to_index_item( (array) $post ); // Try adding this item to the buffer. if ( true === $buffer->append( $current_item['xml'] ) ) { $last_sitemap_id = $post['ID']; $buffer->view_time( $current_item['last_modified'] ); } else { // Otherwise stop looping through posts. break; } } } // If no items were added, return false. if ( true === $buffer->is_empty() ) { return false; } $this->librarian->store_sitemap_data( $number, $index_type, $buffer->contents(), $buffer->last_modified() ); /* * Now report back with the ID of the last sitemap post ID to * be successfully added, whether there are any sitemap posts * left, and the most recent modification time seen. */ return array( 'last_id' => $last_sitemap_id, 'any_left' => $any_sitemaps_left, 'last_modified' => $buffer->last_modified(), ); }