Audio
1 day ago
Video
1 day ago
AttachmentMetaData.php
1 day ago
AttachmentUrl.php
1 day ago
AudioPlayer.php
1 day ago
AvailableSizes.php
1 day ago
Dimensions.php
1 day ago
Download.php
1 day ago
ExifData.php
1 day ago
FileLinkToUrl.php
1 day ago
FileName.php
1 day ago
FileSize.php
1 day ago
Link.php
1 day ago
NestedAttachmentMetaData.php
1 day ago
NumberFormat.php
1 day ago
PostMimeType.php
1 day ago
PreviewViewLink.php
1 day ago
VideoEmbed.php
1 day ago
ExifData.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Media; |
| 6 | |
| 7 | use AC\Exception\ValueNotFoundException; |
| 8 | use AC\Formatter; |
| 9 | use AC\Helper\WpDateFormat; |
| 10 | use AC\Type\Value; |
| 11 | use DateTimeZone; |
| 12 | |
| 13 | class ExifData implements Formatter |
| 14 | { |
| 15 | private string $exif_key; |
| 16 | |
| 17 | public function __construct(string $exif_key) |
| 18 | { |
| 19 | $this->exif_key = $exif_key; |
| 20 | } |
| 21 | |
| 22 | public function format(Value $value): Value |
| 23 | { |
| 24 | $exif_value = $value->get_value()[$this->exif_key] ?? null; |
| 25 | |
| 26 | if (null === $exif_value) { |
| 27 | throw ValueNotFoundException::from_id($value->get_id()); |
| 28 | } |
| 29 | |
| 30 | switch ($this->exif_key) { |
| 31 | case 'created_timestamp' : |
| 32 | $timestamp = (int)$exif_value; |
| 33 | |
| 34 | if (! $timestamp) { |
| 35 | throw ValueNotFoundException::from_id($value->get_id()); |
| 36 | } |
| 37 | |
| 38 | return $value->with_value( |
| 39 | wp_date( |
| 40 | WpDateFormat::date_time(), |
| 41 | $timestamp, |
| 42 | new DateTimeZone('UTC') |
| 43 | ) |
| 44 | ); |
| 45 | case 'keywords' : |
| 46 | if (! is_array($exif_value)) { |
| 47 | throw ValueNotFoundException::from_id($value->get_id()); |
| 48 | } |
| 49 | |
| 50 | return (new Formatter\ImplodeRecursive())->format($value->with_value($exif_value)); |
| 51 | |
| 52 | default: |
| 53 | return $value->with_value($exif_value); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } |
| 58 |