| @@ 694-753 (lines=60) @@ | ||
| 691 | * @type string $last_modified The most recent timestamp to appear on the sitemap. |
|
| 692 | * } |
|
| 693 | */ |
|
| 694 | public function build_one_image_sitemap( $number, $from_id ) { |
|
| 695 | $last_post_id = $from_id; |
|
| 696 | $any_posts_left = true; |
|
| 697 | ||
| 698 | if ( $this->logger ) { |
|
| 699 | $debug_name = jp_sitemap_filename( JP_IMAGE_SITEMAP_TYPE, $number ); |
|
| 700 | $this->logger->report( "-- Building $debug_name" ); |
|
| 701 | } |
|
| 702 | ||
| 703 | $buffer = new Jetpack_Sitemap_Buffer_Image( |
|
| 704 | JP_SITEMAP_MAX_ITEMS, |
|
| 705 | JP_SITEMAP_MAX_BYTES |
|
| 706 | ); |
|
| 707 | ||
| 708 | // Add as many items to the buffer as possible. |
|
| 709 | while ( false === $buffer->is_full() ) { |
|
| 710 | $posts = $this->librarian->query_images_after_id( |
|
| 711 | $last_post_id, JP_SITEMAP_BATCH_SIZE |
|
| 712 | ); |
|
| 713 | ||
| 714 | if ( null == $posts ) { // WPCS: loose comparison ok. |
|
| 715 | $any_posts_left = false; |
|
| 716 | break; |
|
| 717 | } |
|
| 718 | ||
| 719 | foreach ( $posts as $post ) { |
|
| 720 | $current_item = $this->image_post_to_sitemap_item( $post ); |
|
| 721 | ||
| 722 | if ( true === $buffer->append( $current_item['xml'] ) ) { |
|
| 723 | $last_post_id = $post->ID; |
|
| 724 | $buffer->view_time( $current_item['last_modified'] ); |
|
| 725 | } else { |
|
| 726 | break; |
|
| 727 | } |
|
| 728 | } |
|
| 729 | } |
|
| 730 | ||
| 731 | // If no items were added, return false. |
|
| 732 | if ( true === $buffer->is_empty() ) { |
|
| 733 | return false; |
|
| 734 | } |
|
| 735 | ||
| 736 | // Store the buffer as the content of a jp_sitemap post. |
|
| 737 | $this->librarian->store_sitemap_data( |
|
| 738 | $number, |
|
| 739 | JP_IMAGE_SITEMAP_TYPE, |
|
| 740 | $buffer->contents(), |
|
| 741 | $buffer->last_modified() |
|
| 742 | ); |
|
| 743 | ||
| 744 | /* |
|
| 745 | * Now report back with the ID of the last post to be |
|
| 746 | * successfully added and whether there are any posts left. |
|
| 747 | */ |
|
| 748 | return array( |
|
| 749 | 'last_id' => $last_post_id, |
|
| 750 | 'any_left' => $any_posts_left, |
|
| 751 | 'last_modified' => $buffer->last_modified(), |
|
| 752 | ); |
|
| 753 | } |
|
| 754 | ||
| 755 | /** |
|
| 756 | * Build and store a single video sitemap. Returns false if no sitemap is built. |
|
| @@ 772-832 (lines=61) @@ | ||
| 769 | * @type string $last_modified The most recent timestamp to appear on the sitemap. |
|
| 770 | * } |
|
| 771 | */ |
|
| 772 | public function build_one_video_sitemap( $number, $from_id ) { |
|
| 773 | $last_post_id = $from_id; |
|
| 774 | $any_posts_left = true; |
|
| 775 | ||
| 776 | if ( $this->logger ) { |
|
| 777 | $debug_name = jp_sitemap_filename( JP_VIDEO_SITEMAP_TYPE, $number ); |
|
| 778 | $this->logger->report( "-- Building $debug_name" ); |
|
| 779 | } |
|
| 780 | ||
| 781 | $buffer = new Jetpack_Sitemap_Buffer_Video( |
|
| 782 | JP_SITEMAP_MAX_ITEMS, |
|
| 783 | JP_SITEMAP_MAX_BYTES |
|
| 784 | ); |
|
| 785 | ||
| 786 | // Add as many items to the buffer as possible. |
|
| 787 | while ( false === $buffer->is_full() ) { |
|
| 788 | $posts = $this->librarian->query_videos_after_id( |
|
| 789 | $last_post_id, JP_SITEMAP_BATCH_SIZE |
|
| 790 | ); |
|
| 791 | ||
| 792 | if ( null == $posts ) { // WPCS: loose comparison ok. |
|
| 793 | $any_posts_left = false; |
|
| 794 | break; |
|
| 795 | } |
|
| 796 | ||
| 797 | foreach ( $posts as $post ) { |
|
| 798 | $current_item = $this->video_post_to_sitemap_item( $post ); |
|
| 799 | ||
| 800 | if ( true === $buffer->append( $current_item['xml'] ) ) { |
|
| 801 | $last_post_id = $post->ID; |
|
| 802 | $buffer->view_time( $current_item['last_modified'] ); |
|
| 803 | } else { |
|
| 804 | break; |
|
| 805 | } |
|
| 806 | } |
|
| 807 | } |
|
| 808 | ||
| 809 | // If no items were added, return false. |
|
| 810 | if ( true === $buffer->is_empty() ) { |
|
| 811 | return false; |
|
| 812 | } |
|
| 813 | ||
| 814 | if ( false === $buffer->is_empty() ) { |
|
| 815 | $this->librarian->store_sitemap_data( |
|
| 816 | $number, |
|
| 817 | JP_VIDEO_SITEMAP_TYPE, |
|
| 818 | $buffer->contents(), |
|
| 819 | $buffer->last_modified() |
|
| 820 | ); |
|
| 821 | } |
|
| 822 | ||
| 823 | /* |
|
| 824 | * Now report back with the ID of the last post to be |
|
| 825 | * successfully added and whether there are any posts left. |
|
| 826 | */ |
|
| 827 | return array( |
|
| 828 | 'last_id' => $last_post_id, |
|
| 829 | 'any_left' => $any_posts_left, |
|
| 830 | 'last_modified' => $buffer->last_modified(), |
|
| 831 | ); |
|
| 832 | } |
|
| 833 | ||
| 834 | /** |
|
| 835 | * Build and store a single page sitemap index. Return false if no index is built. |
|