Attachments.php
2 days ago
Author.php
2 days ago
BeforeMoreContent.php
2 days ago
CommentCount.php
2 days ago
CommentsForPostLink.php
2 days ago
ContentExcerpt.php
2 days ago
DatePublishFormatted.php
2 days ago
Depth.php
2 days ago
DescriptivePostStatus.php
2 days ago
DiscussionStatus.php
2 days ago
Excerpt.php
2 days ago
ExcerptMissingMessage.php
2 days ago
ExcerptRaw.php
2 days ago
FeaturedImage.php
2 days ago
HasCommentStatus.php
2 days ago
IsPasswordProtected.php
2 days ago
IsSticky.php
2 days ago
LastModifiedAuthor.php
2 days ago
Meta.php
2 days ago
ModifiedDate.php
2 days ago
Order.php
2 days ago
PageTemplate.php
2 days ago
Path.php
2 days ago
Permalink.php
2 days ago
PingStatus.php
2 days ago
PostContent.php
2 days ago
PostDate.php
2 days ago
PostDateTimestamp.php
2 days ago
PostFormat.php
2 days ago
PostFormatIcon.php
2 days ago
PostFormatLabel.php
2 days ago
PostLink.php
2 days ago
PostParentId.php
2 days ago
PostReferences.php
2 days ago
PostStatus.php
2 days ago
PostStatusIcon.php
2 days ago
PostTerms.php
2 days ago
PostTermsOriginal.php
2 days ago
PostTitle.php
2 days ago
Property.php
2 days ago
ShortLink.php
2 days ago
Shortcodes.php
2 days ago
Slug.php
2 days ago
DatePublishFormatted.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Post; |
| 6 | |
| 7 | use AC\Exception\ValueNotFoundException; |
| 8 | use AC\Formatter; |
| 9 | use AC\Helper; |
| 10 | use AC\Helper\WpDateFormat; |
| 11 | use AC\Type\Value; |
| 12 | |
| 13 | class DatePublishFormatted implements Formatter |
| 14 | { |
| 15 | public function format(Value $value): Value |
| 16 | { |
| 17 | $post = get_post((int)$value->get_id()); |
| 18 | |
| 19 | if (! $post) { |
| 20 | throw ValueNotFoundException::from_id($value->get_id()); |
| 21 | } |
| 22 | |
| 23 | $date = (string)$value; |
| 24 | |
| 25 | switch ($post->post_status) { |
| 26 | // Icons |
| 27 | case 'private': |
| 28 | case 'draft': |
| 29 | case 'pending': |
| 30 | return (new PostStatusIcon())->format( |
| 31 | new Value($post->ID, $post) |
| 32 | ); |
| 33 | case 'future': |
| 34 | return $value->with_value( |
| 35 | sprintf( |
| 36 | '%s %s: <em>%s</em>', |
| 37 | (new PostStatusIcon())->format(new Value($post->ID, $post)), |
| 38 | __('Scheduled'), |
| 39 | $date |
| 40 | ) |
| 41 | ); |
| 42 | |
| 43 | // Tooltip |
| 44 | default: |
| 45 | $timestamp = strtotime($post->post_date_gmt); |
| 46 | |
| 47 | if (false === $timestamp) { |
| 48 | throw ValueNotFoundException::from_id($value->get_id()); |
| 49 | } |
| 50 | |
| 51 | return $value->with_value( |
| 52 | Helper\Html::create()->tooltip( |
| 53 | $date, |
| 54 | sprintf( |
| 55 | '%s <br><em>%s</em>', |
| 56 | __('Published'), |
| 57 | wp_date( |
| 58 | WpDateFormat::date_time(), |
| 59 | $timestamp |
| 60 | ) |
| 61 | ) |
| 62 | ) |
| 63 | ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | } |
| 68 |