wordpress-activitypub/includes/transformer/class-attachment.php
Matthias Pfefferle cbbbd70890
A better default content handling based on the Object Type (#661)
* nicer default handling!

* use attachment based on the object type

* fix typo

* C&P issue

* update settings

* add default post format

* mixed up `post_format` with `object_type`

* use h2 instead of strong

* add theme support for `post-formats`

if using that feature for ActivityPub

* use Note instead of `image`, `video` and `gallery`

* add `alt` support for images

fix #94

* set type to `Note` if post-type has no title support

* better check

* hide "Post content" when WordPress-Post-Format is selected

* add ACTIVITYPUB_DEFAULT_OBJECT_TYPE const

* move some code

* use note as default
2024-02-29 14:47:10 +01:00

61 lines
1.3 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 {
/**
* Generates all Media Attachments for a Post.
*
* @return array The Attachments.
*/
protected function get_attachment() {
$mime_type = get_post_mime_type( $this->wp_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->wp_object->ID ),
'mediaType' => $mime_type,
);
$alt = \get_post_meta( $this->wp_object->ID, '_wp_attachment_image_alt', true );
if ( $alt ) {
$attachment['name'] = $alt;
}
return $attachment;
}
/**
* Returns the ActivityStreams 2.0 Object-Type for a Post based on the
* settings and the Post-Type.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
*
* @return string The Object-Type.
*/
protected function get_type() {
return 'Note';
}
}