| 1 |
<?php |
| 2 |
namespace Activitypub\Transformer; |
| 3 |
|
| 4 |
use Activitypub\Transformer\Post; |
| 5 |
|
| 6 |
/** |
| 7 |
* WordPress Attachment Transformer |
| 8 |
* |
| 9 |
* The Attachment Transformer is responsible for transforming a WP_Post object into different other |
| 10 |
* Object-Types. |
| 11 |
* |
| 12 |
* Currently supported are: |
| 13 |
* |
| 14 |
* - Activitypub\Activity\Base_Object |
| 15 |
*/ |
| 16 |
class Attachment extends Post { |
| 17 |
/** |
| 18 |
* Generates all Media Attachments for a Post. |
| 19 |
* |
| 20 |
* @return array The Attachments. |
| 21 |
*/ |
| 22 |
protected function get_attachment() { |
| 23 |
$mime_type = get_post_mime_type( $this->wp_object->ID ); |
| 24 |
$media_type = preg_replace( '/(\/[a-zA-Z]+)/i', '', $mime_type ); |
| 25 |
|
| 26 |
switch ( $media_type ) { |
| 27 |
case 'audio': |
| 28 |
case 'video': |
| 29 |
$type = 'Document'; |
| 30 |
break; |
| 31 |
case 'image': |
| 32 |
$type = 'Image'; |
| 33 |
break; |
| 34 |
} |
| 35 |
|
| 36 |
$attachment = array( |
| 37 |
'type' => $type, |
| 38 |
'url' => wp_get_attachment_url( $this->wp_object->ID ), |
| 39 |
'mediaType' => $mime_type, |
| 40 |
); |
| 41 |
|
| 42 |
$alt = \get_post_meta( $this->wp_object->ID, '_wp_attachment_image_alt', true ); |
| 43 |
if ( $alt ) { |
| 44 |
$attachment['name'] = $alt; |
| 45 |
} |
| 46 |
|
| 47 |
return $attachment; |
| 48 |
} |
| 49 |
} |
| 50 |
|