wordpress-activitypub/includes/transformer/class-attachment.php
André Menrath 6c6d9076a8
Some checks are pending
PHP_CodeSniffer / phpcs (push) Waiting to run
Unit Testing / phpunit (5.6, 6.2) (push) Waiting to run
Unit Testing / phpunit (7.0) (push) Waiting to run
Unit Testing / phpunit (7.2) (push) Waiting to run
Unit Testing / phpunit (7.3) (push) Waiting to run
Unit Testing / phpunit (7.4) (push) Waiting to run
Unit Testing / phpunit (8.0) (push) Waiting to run
Unit Testing / phpunit (8.1) (push) Waiting to run
Unit Testing / phpunit (8.2) (push) Waiting to run
Unit Testing / phpunit (latest) (push) Waiting to run
WIP: Rewrite of transformer management
2023-12-22 16:18:18 +01:00

67 lines
1.4 KiB
PHP

<?php
namespace Activitypub\Transformer;
use Activitypub\Transformer\Post;
/**
* WordPress Attachment Transformer
*
* The Attachment Transformer is responsible for transforming a WP_Post object into different other
* Object-Types.
*
* Currently supported are:
*
* - Activitypub\Activity\Base_Object
*/
class Attachment extends Post {
/**
* Getter function for the name of the transformer.
*
* @return string name
*/
public function get_name() {
return 'activitypub/attachment';
}
/**
* Getter function for the display name (label/title) of the transformer.
*
* @return string name
*/
public function get_label() {
return 'Built-In Transformer for WordPress Attachments';
}
/**
* Generates all Media Attachments for a Post.
*
* @return array The Attachments.
*/
protected function get_attachment() {
$mime_type = get_post_mime_type( $this->object->ID );
$media_type = preg_replace( '/(\/[a-zA-Z]+)/i', '', $mime_type );
switch ( $media_type ) {
case 'audio':
case 'video':
$type = 'Document';
break;
case 'image':
$type = 'Image';
break;
}
$attachment = array(
'type' => $type,
'url' => wp_get_attachment_url( $this->object->ID ),
'mediaType' => $mime_type,
);
$alt = \get_post_meta( $this->object->ID, '_wp_attachment_image_alt', true );
if ( $alt ) {
$attachment['name'] = $alt;
}
return $attachment;
}
}