| 1 |
<?php |
| 2 |
/** |
| 3 |
* Date Page Metadata Builder class |
| 4 |
* |
| 5 |
* @package Parsely |
| 6 |
* @since 3.4.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
namespace Parsely\Metadata; |
| 12 |
|
| 13 |
use Parsely\Utils\Utils; |
| 14 |
|
| 15 |
/** |
| 16 |
* Implements abstract Metadata Builder class to generate the metadata array |
| 17 |
* for a date page. |
| 18 |
* |
| 19 |
* @since 3.4.0 |
| 20 |
*/ |
| 21 |
class Date_Builder extends Metadata_Builder { |
| 22 |
/** |
| 23 |
* Generates the metadata object by calling the build_* methods and |
| 24 |
* returns the value. |
| 25 |
* |
| 26 |
* @since 3.4.0 |
| 27 |
* |
| 28 |
* @return array<string, mixed> |
| 29 |
*/ |
| 30 |
public function get_metadata(): array { |
| 31 |
$this->build_basic(); |
| 32 |
$this->build_headline(); |
| 33 |
$this->build_url(); |
| 34 |
|
| 35 |
return $this->metadata; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Populates the `headline` field in the metadata object. |
| 40 |
* |
| 41 |
* @since 3.4.0 |
| 42 |
*/ |
| 43 |
private function build_headline(): void { |
| 44 |
$site_date_format = Utils::get_date_format(); |
| 45 |
|
| 46 |
if ( is_year() ) { |
| 47 |
/* translators: %s: Archive year */ |
| 48 |
$this->metadata['headline'] = sprintf( __( 'Yearly Archive - %s', 'wp-parsely' ), get_the_time( 'Y' ) ); |
| 49 |
} elseif ( is_month() ) { |
| 50 |
/* translators: %s: Archive month, formatted as F, Y */ |
| 51 |
$this->metadata['headline'] = sprintf( __( 'Monthly Archive - %s', 'wp-parsely' ), get_the_time( 'F, Y' ) ); |
| 52 |
} elseif ( is_day() ) { |
| 53 |
/* translators: %s: Archive day, formatted as F jS, Y */ |
| 54 |
$this->metadata['headline'] = sprintf( __( 'Daily Archive - %s', 'wp-parsely' ), get_the_time( $site_date_format ) ); |
| 55 |
} elseif ( is_time() ) { |
| 56 |
$site_time_format = Utils::get_time_format(); |
| 57 |
/* translators: %s: Archive time, formatted as F jS g:i:s A */ |
| 58 |
$this->metadata['headline'] = sprintf( __( 'Hourly, Minutely, or Secondly Archive - %s', 'wp-parsely' ), get_the_time( "{$site_date_format} {$site_time_format}" ) ); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|