@@ 745-804 (lines=60) @@ | ||
742 | * @type string $last_modified The most recent timestamp to appear on the sitemap. |
|
743 | * } |
|
744 | */ |
|
745 | public function build_one_image_sitemap( $number, $from_id ) { |
|
746 | $last_post_id = $from_id; |
|
747 | $any_posts_left = true; |
|
748 | ||
749 | if ( $this->logger ) { |
|
750 | $debug_name = jp_sitemap_filename( JP_IMAGE_SITEMAP_TYPE, $number ); |
|
751 | $this->logger->report( "-- Building $debug_name" ); |
|
752 | } |
|
753 | ||
754 | $buffer = new Jetpack_Sitemap_Buffer_Image( |
|
755 | JP_SITEMAP_MAX_ITEMS, |
|
756 | JP_SITEMAP_MAX_BYTES |
|
757 | ); |
|
758 | ||
759 | // Add as many items to the buffer as possible. |
|
760 | while ( false === $buffer->is_full() ) { |
|
761 | $posts = $this->librarian->query_images_after_id( |
|
762 | $last_post_id, |
|
763 | JP_SITEMAP_BATCH_SIZE |
|
764 | ); |
|
765 | ||
766 | if ( null == $posts ) { // WPCS: loose comparison ok. |
|
767 | $any_posts_left = false; |
|
768 | break; |
|
769 | } |
|
770 | ||
771 | foreach ( $posts as $post ) { |
|
772 | $current_item = $this->image_post_to_sitemap_item( $post ); |
|
773 | ||
774 | if ( true === $buffer->append( $current_item['xml'] ) ) { |
|
775 | $last_post_id = $post->ID; |
|
776 | $buffer->view_time( $current_item['last_modified'] ); |
|
777 | } else { |
|
778 | break; |
|
779 | } |
|
780 | } |
|
781 | } |
|
782 | ||
783 | // If no items were added, return false. |
|
784 | if ( true === $buffer->is_empty() ) { |
|
785 | return false; |
|
786 | } |
|
787 | ||
788 | // Store the buffer as the content of a jp_sitemap post. |
|
789 | $this->librarian->store_sitemap_data( |
|
790 | $number, |
|
791 | JP_IMAGE_SITEMAP_TYPE, |
|
792 | $buffer->contents(), |
|
793 | $buffer->last_modified() |
|
794 | ); |
|
795 | ||
796 | /* |
|
797 | * Now report back with the ID of the last post to be |
|
798 | * successfully added and whether there are any posts left. |
|
799 | */ |
|
800 | return array( |
|
801 | 'last_id' => $last_post_id, |
|
802 | 'any_left' => $any_posts_left, |
|
803 | 'last_modified' => $buffer->last_modified(), |
|
804 | ); |
|
805 | } |
|
806 | ||
807 | /** |
|
@@ 824-884 (lines=61) @@ | ||
821 | * @type string $last_modified The most recent timestamp to appear on the sitemap. |
|
822 | * } |
|
823 | */ |
|
824 | public function build_one_video_sitemap( $number, $from_id ) { |
|
825 | $last_post_id = $from_id; |
|
826 | $any_posts_left = true; |
|
827 | ||
828 | if ( $this->logger ) { |
|
829 | $debug_name = jp_sitemap_filename( JP_VIDEO_SITEMAP_TYPE, $number ); |
|
830 | $this->logger->report( "-- Building $debug_name" ); |
|
831 | } |
|
832 | ||
833 | $buffer = new Jetpack_Sitemap_Buffer_Video( |
|
834 | JP_SITEMAP_MAX_ITEMS, |
|
835 | JP_SITEMAP_MAX_BYTES |
|
836 | ); |
|
837 | ||
838 | // Add as many items to the buffer as possible. |
|
839 | while ( false === $buffer->is_full() ) { |
|
840 | $posts = $this->librarian->query_videos_after_id( |
|
841 | $last_post_id, |
|
842 | JP_SITEMAP_BATCH_SIZE |
|
843 | ); |
|
844 | ||
845 | if ( null == $posts ) { // WPCS: loose comparison ok. |
|
846 | $any_posts_left = false; |
|
847 | break; |
|
848 | } |
|
849 | ||
850 | foreach ( $posts as $post ) { |
|
851 | $current_item = $this->video_post_to_sitemap_item( $post ); |
|
852 | ||
853 | if ( true === $buffer->append( $current_item['xml'] ) ) { |
|
854 | $last_post_id = $post->ID; |
|
855 | $buffer->view_time( $current_item['last_modified'] ); |
|
856 | } else { |
|
857 | break; |
|
858 | } |
|
859 | } |
|
860 | } |
|
861 | ||
862 | // If no items were added, return false. |
|
863 | if ( true === $buffer->is_empty() ) { |
|
864 | return false; |
|
865 | } |
|
866 | ||
867 | if ( false === $buffer->is_empty() ) { |
|
868 | $this->librarian->store_sitemap_data( |
|
869 | $number, |
|
870 | JP_VIDEO_SITEMAP_TYPE, |
|
871 | $buffer->contents(), |
|
872 | $buffer->last_modified() |
|
873 | ); |
|
874 | } |
|
875 | ||
876 | /* |
|
877 | * Now report back with the ID of the last post to be |
|
878 | * successfully added and whether there are any posts left. |
|
879 | */ |
|
880 | return array( |
|
881 | 'last_id' => $last_post_id, |
|
882 | 'any_left' => $any_posts_left, |
|
883 | 'last_modified' => $buffer->last_modified(), |
|
884 | ); |
|
885 | } |
|
886 | ||
887 | /** |