| 1 |
<?php |
| 2 |
|
| 3 |
namespace FlyWP\StaticSite\Engine\Incremental; |
| 4 |
|
| 5 |
use FlyWP\StaticSite\Engine\Discovery\HomeSource; |
| 6 |
use FlyWP\StaticSite\Engine\Discovery\WordPressGateway; |
| 7 |
|
| 8 |
/** |
| 9 |
* The list pages that show a post: term archives, and the posts page, author and date archives (type "post") |
| 10 |
* or the post type archive (other types). |
| 11 |
* |
| 12 |
* The change log records these lists before a hard delete. The builder uses the same lists for a post that |
| 13 |
* still exists. Thus a hard-deleted post and a trashed post rebuild the same lists. |
| 14 |
* |
| 15 |
* @since 1.8.0 |
| 16 |
*/ |
| 17 |
class PostLists { |
| 18 |
|
| 19 |
/** |
| 20 |
* @param WordPressGateway $wp Gateway. |
| 21 |
* @param array{id:int, post_type:string, author:int, date:string} $post Post. |
| 22 |
* |
| 23 |
* @return array<int, array{type:string, id:int|null, url:string|null}> |
| 24 |
* type: term (id = term ID), blog, user (id = user ID), date (id = year or year * 100 + month), archive. |
| 25 |
*/ |
| 26 |
public static function for_post( WordPressGateway $wp, array $post ) { |
| 27 |
$lists = []; |
| 28 |
|
| 29 |
foreach ( $wp->post_terms( $post['id'] ) as $term ) { |
| 30 |
$lists[] = [ |
| 31 |
'type' => 'term', |
| 32 |
'id' => $term['id'], |
| 33 |
'url' => $wp->term_link( $term['id'], $term['taxonomy'] ), |
| 34 |
]; |
| 35 |
} |
| 36 |
|
| 37 |
if ( 'post' !== $post['post_type'] ) { |
| 38 |
$lists[] = [ |
| 39 |
'type' => 'archive', |
| 40 |
'id' => null, |
| 41 |
'url' => $wp->post_type_archive_link( $post['post_type'] ), |
| 42 |
]; |
| 43 |
|
| 44 |
return $lists; |
| 45 |
} |
| 46 |
|
| 47 |
$lists[] = [ |
| 48 |
'type' => 'blog', |
| 49 |
'id' => null, |
| 50 |
'url' => HomeSource::blog_url( $wp ), |
| 51 |
]; |
| 52 |
$lists[] = [ |
| 53 |
'type' => 'user', |
| 54 |
'id' => (int) $post['author'], |
| 55 |
'url' => $wp->author_link( $post['author'] ), |
| 56 |
]; |
| 57 |
|
| 58 |
if ( preg_match( '/^(\d{4})-(\d{2})/', (string) $post['date'], $date ) ) { |
| 59 |
$year = (int) $date[1]; |
| 60 |
$month = (int) $date[2]; |
| 61 |
|
| 62 |
$lists[] = [ |
| 63 |
'type' => 'date', |
| 64 |
'id' => $year, |
| 65 |
'url' => $wp->year_link( $year ), |
| 66 |
]; |
| 67 |
$lists[] = [ |
| 68 |
'type' => 'date', |
| 69 |
'id' => $year * 100 + $month, |
| 70 |
'url' => $wp->month_link( $year, $month ), |
| 71 |
]; |
| 72 |
} |
| 73 |
|
| 74 |
return $lists; |
| 75 |
} |
| 76 |
} |
| 77 |
|