| @@ 629-688 (lines=60) @@ | ||
| 626 | * @type string $last_modified The most recent timestamp to appear on the sitemap. | |
| 627 | * } | |
| 628 | */ | |
| 629 | 	public function build_one_image_sitemap( $number, $from_id ) { | |
| 630 | $last_post_id = $from_id; | |
| 631 | $any_posts_left = true; | |
| 632 | ||
| 633 | 		if ( $this->logger ) { | |
| 634 | $debug_name = jp_sitemap_filename( JP_IMAGE_SITEMAP_TYPE, $number ); | |
| 635 | $this->logger->report( "-- Building $debug_name" ); | |
| 636 | } | |
| 637 | ||
| 638 | $buffer = new Jetpack_Sitemap_Buffer_Image( | |
| 639 | JP_SITEMAP_MAX_ITEMS, | |
| 640 | JP_SITEMAP_MAX_BYTES | |
| 641 | ); | |
| 642 | ||
| 643 | // Add as many items to the buffer as possible. | |
| 644 | 		while ( false === $buffer->is_full() ) { | |
| 645 | $posts = $this->librarian->query_images_after_id( | |
| 646 | $last_post_id, JP_SITEMAP_BATCH_SIZE | |
| 647 | ); | |
| 648 | ||
| 649 | 			if ( null == $posts ) { // WPCS: loose comparison ok. | |
| 650 | $any_posts_left = false; | |
| 651 | break; | |
| 652 | } | |
| 653 | ||
| 654 | 			foreach ( $posts as $post ) { | |
| 655 | $current_item = $this->image_post_to_sitemap_item( $post ); | |
| 656 | ||
| 657 | 				if ( true === $buffer->append( $current_item['xml'] ) ) { | |
| 658 | $last_post_id = $post->ID; | |
| 659 | $buffer->view_time( $current_item['last_modified'] ); | |
| 660 | 				} else { | |
| 661 | break; | |
| 662 | } | |
| 663 | } | |
| 664 | } | |
| 665 | ||
| 666 | // If no items were added, return false. | |
| 667 | 		if ( true === $buffer->is_empty() ) { | |
| 668 | return false; | |
| 669 | } | |
| 670 | ||
| 671 | // Store the buffer as the content of a jp_sitemap post. | |
| 672 | $this->librarian->store_sitemap_data( | |
| 673 | $number, | |
| 674 | JP_IMAGE_SITEMAP_TYPE, | |
| 675 | $buffer->contents(), | |
| 676 | $buffer->last_modified() | |
| 677 | ); | |
| 678 | ||
| 679 | /* | |
| 680 | * Now report back with the ID of the last post to be | |
| 681 | * successfully added and whether there are any posts left. | |
| 682 | */ | |
| 683 | return array( | |
| 684 | 'last_id' => $last_post_id, | |
| 685 | 'any_left' => $any_posts_left, | |
| 686 | 'last_modified' => $buffer->last_modified(), | |
| 687 | ); | |
| 688 | } | |
| 689 | ||
| 690 | /** | |
| 691 | * Build and store a single video sitemap. Returns false if no sitemap is built. | |
| @@ 707-767 (lines=61) @@ | ||
| 704 | * @type string $last_modified The most recent timestamp to appear on the sitemap. | |
| 705 | * } | |
| 706 | */ | |
| 707 | 	public function build_one_video_sitemap( $number, $from_id ) { | |
| 708 | $last_post_id = $from_id; | |
| 709 | $any_posts_left = true; | |
| 710 | ||
| 711 | 		if ( $this->logger ) { | |
| 712 | $debug_name = jp_sitemap_filename( JP_VIDEO_SITEMAP_TYPE, $number ); | |
| 713 | $this->logger->report( "-- Building $debug_name" ); | |
| 714 | } | |
| 715 | ||
| 716 | $buffer = new Jetpack_Sitemap_Buffer_Video( | |
| 717 | JP_SITEMAP_MAX_ITEMS, | |
| 718 | JP_SITEMAP_MAX_BYTES | |
| 719 | ); | |
| 720 | ||
| 721 | // Add as many items to the buffer as possible. | |
| 722 | 		while ( false === $buffer->is_full() ) { | |
| 723 | $posts = $this->librarian->query_videos_after_id( | |
| 724 | $last_post_id, JP_SITEMAP_BATCH_SIZE | |
| 725 | ); | |
| 726 | ||
| 727 | 			if ( null == $posts ) { // WPCS: loose comparison ok. | |
| 728 | $any_posts_left = false; | |
| 729 | break; | |
| 730 | } | |
| 731 | ||
| 732 | 			foreach ( $posts as $post ) { | |
| 733 | $current_item = $this->video_post_to_sitemap_item( $post ); | |
| 734 | ||
| 735 | 				if ( true === $buffer->append( $current_item['xml'] ) ) { | |
| 736 | $last_post_id = $post->ID; | |
| 737 | $buffer->view_time( $current_item['last_modified'] ); | |
| 738 | 				} else { | |
| 739 | break; | |
| 740 | } | |
| 741 | } | |
| 742 | } | |
| 743 | ||
| 744 | // If no items were added, return false. | |
| 745 | 		if ( true === $buffer->is_empty() ) { | |
| 746 | return false; | |
| 747 | } | |
| 748 | ||
| 749 | 		if ( false === $buffer->is_empty() ) { | |
| 750 | $this->librarian->store_sitemap_data( | |
| 751 | $number, | |
| 752 | JP_VIDEO_SITEMAP_TYPE, | |
| 753 | $buffer->contents(), | |
| 754 | $buffer->last_modified() | |
| 755 | ); | |
| 756 | } | |
| 757 | ||
| 758 | /* | |
| 759 | * Now report back with the ID of the last post to be | |
| 760 | * successfully added and whether there are any posts left. | |
| 761 | */ | |
| 762 | return array( | |
| 763 | 'last_id' => $last_post_id, | |
| 764 | 'any_left' => $any_posts_left, | |
| 765 | 'last_modified' => $buffer->last_modified(), | |
| 766 | ); | |
| 767 | } | |
| 768 | ||
| 769 | /** | |
| 770 | * Build and store a single page sitemap index. Return false if no index is built. | |