PluginProbe
ActivityPub / 2.5.0
ActivityPub v2.5.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / transformer / class-attachment.php

class-attachment.php in ActivityPub 2.5.0, at includes/transformer/class-attachment.php

62 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
51 * Returns the ActivityStreams 2.0 Object-Type for a Post based on the
52 * settings and the Post-Type.
53 *
54 * @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
55 *
56 * @return string The Object-Type.
57 */
58 protected function get_type() {
59 return 'Note';
60 }
61 }
62