PluginProbe
ActivityPub / 9.2.2
ActivityPub v9.2.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 9.2.2, at includes/transformer/class-attachment.php

73 lines 1.7 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 * Redaction is inherited from {@see Post::is_redacted()}: `is_post_publicly_queryable()`
21 * already resolves an attachment's own visibility, password, post-type support, and — for
22 * attached media — its parent's visibility, so no attachment-specific override is needed.
23 */
24 class Attachment extends Post {
25 /**
26 * Generates all Media Attachments for a Post.
27 *
28 * @return array The Attachments.
29 */
30 protected function get_attachment() {
31 $mime_type = \get_post_mime_type( $this->item->ID );
32 $mime_type_parts = \explode( '/', $mime_type );
33 $type = '';
34
35 switch ( $mime_type_parts[0] ) {
36 case 'audio':
37 $type = 'Audio';
38 break;
39 case 'video':
40 $type = 'Video';
41 break;
42 case 'image':
43 $type = 'Image';
44 break;
45 }
46
47 $attachment = array(
48 'type' => $type,
49 'url' => \wp_get_attachment_url( $this->item->ID ),
50 'mediaType' => $mime_type,
51 );
52
53 $alt = \get_post_meta( $this->item->ID, '_wp_attachment_image_alt', true );
54 if ( $alt ) {
55 $attachment['name'] = $alt;
56 }
57
58 return $attachment;
59 }
60
61 /**
62 * Returns the ActivityStreams 2.0 Object-Type for a Post based on the
63 * settings and the Post-Type.
64 *
65 * @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
66 *
67 * @return string The Object-Type.
68 */
69 protected function get_type() {
70 return 'Note';
71 }
72 }
73