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