PluginProbe
ActivityPub / 7.8.2
ActivityPub v7.8.2
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 7.8.2, at includes/transformer/class-attachment.php

69 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $type = 'Audio';
34 break;
35 case 'video':
36 $type = 'Video';
37 break;
38 case 'image':
39 $type = 'Image';
40 break;
41 }
42
43 $attachment = array(
44 'type' => $type,
45 'url' => wp_get_attachment_url( $this->item->ID ),
46 'mediaType' => $mime_type,
47 );
48
49 $alt = \get_post_meta( $this->item->ID, '_wp_attachment_image_alt', true );
50 if ( $alt ) {
51 $attachment['name'] = $alt;
52 }
53
54 return $attachment;
55 }
56
57 /**
58 * Returns the ActivityStreams 2.0 Object-Type for a Post based on the
59 * settings and the Post-Type.
60 *
61 * @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
62 *
63 * @return string The Object-Type.
64 */
65 protected function get_type() {
66 return 'Note';
67 }
68 }
69