| 1 |
<?php |
| 2 |
/** |
| 3 |
* Attachment Transformer Class file. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub\Transformer; |
| 9 |
|
| 10 |
/** |
| 11 |
* WordPress Attachment Transformer. |
| 12 |
* |
| 13 |
* The Attachment Transformer is responsible for transforming a WP_Post object into different other |
| 14 |
* Object-Types. |
| 15 |
* |
| 16 |
* Currently supported are: |
| 17 |
* |
| 18 |
* - Activitypub\Activity\Base_Object |
| 19 |
*/ |
| 20 |
class Attachment extends Post { |
| 21 |
/** |
| 22 |
* Generates all Media Attachments for a Post. |
| 23 |
* |
| 24 |
* @return array The Attachments. |
| 25 |
*/ |
| 26 |
protected function get_attachment() { |
| 27 |
$mime_type = \get_post_mime_type( $this->item->ID ); |
| 28 |
$mime_type_parts = \explode( '/', $mime_type ); |
| 29 |
$type = ''; |
| 30 |
|
| 31 |
switch ( $mime_type_parts[0] ) { |
| 32 |
case 'audio': |
| 33 |
case 'video': |
| 34 |
$type = 'Document'; |
| 35 |
break; |
| 36 |
case 'image': |
| 37 |
$type = 'Image'; |
| 38 |
break; |
| 39 |
} |
| 40 |
|
| 41 |
$attachment = array( |
| 42 |
'type' => $type, |
| 43 |
'url' => wp_get_attachment_url( $this->item->ID ), |
| 44 |
'mediaType' => $mime_type, |
| 45 |
); |
| 46 |
|
| 47 |
$alt = \get_post_meta( $this->item->ID, '_wp_attachment_image_alt', true ); |
| 48 |
if ( $alt ) { |
| 49 |
$attachment['name'] = $alt; |
| 50 |
} |
| 51 |
|
| 52 |
return $attachment; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Returns the ActivityStreams 2.0 Object-Type for a Post based on the |
| 57 |
* settings and the Post-Type. |
| 58 |
* |
| 59 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types |
| 60 |
* |
| 61 |
* @return string The Object-Type. |
| 62 |
*/ |
| 63 |
protected function get_type() { |
| 64 |
return 'Note'; |
| 65 |
} |
| 66 |
} |
| 67 |
|