PluginProbe
ActivityPub / 5.1.0
ActivityPub v5.1.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-activity-object.php

class-activity-object.php in ActivityPub 5.1.0, at includes/transformer/class-activity-object.php

144 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Activity Object Transformer Class.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\Transformer;
9
10 /**
11 * Activity Object Transformer Class.
12 */
13 class Activity_Object extends Base {
14 /**
15 * Transform the WordPress Object into an ActivityPub Object.
16 *
17 * @return Base_Object The ActivityPub Object.
18 */
19 public function to_object() {
20 $activity_object = $this->transform_object_properties( $this->item );
21
22 if ( \is_wp_error( $activity_object ) ) {
23 return $activity_object;
24 }
25
26 $activity_object = $this->set_audience( $activity_object );
27
28 return $activity_object;
29 }
30
31 /**
32 * Get the attributed to.
33 *
34 * @return string The attributed to.
35 */
36 public function get_attributed_to() {
37 return $this->item->get_attributed_to();
38 }
39
40 /**
41 * Helper function to get the @-Mentions from the post content.
42 *
43 * @return array The list of @-Mentions.
44 */
45 protected function get_mentions() {
46 /**
47 * Filter the mentions in the post content.
48 *
49 * @param array $mentions The mentions.
50 * @param string $content The post content.
51 * @param WP_Post $post The post object.
52 *
53 * @return array The filtered mentions.
54 */
55 return apply_filters(
56 'activitypub_extract_mentions',
57 array(),
58 $this->item->get_content() . ' ' . $this->item->get_summary(),
59 $this->item
60 );
61 }
62
63 /**
64 * Returns the content map for the post.
65 *
66 * @return array The content map for the post.
67 */
68 protected function get_content_map() {
69 $content = $this->item->get_content();
70
71 if ( ! $content ) {
72 return null;
73 }
74
75 return array(
76 $this->get_locale() => $content,
77 );
78 }
79
80 /**
81 * Returns the name map for the post.
82 *
83 * @return array The name map for the post.
84 */
85 protected function get_name_map() {
86 $name = $this->item->get_name();
87
88 if ( ! $name ) {
89 return null;
90 }
91
92 return array(
93 $this->get_locale() => $name,
94 );
95 }
96
97 /**
98 * Returns the summary map for the post.
99 *
100 * @return array The summary map for the post.
101 */
102 protected function get_summary_map() {
103 $summary = $this->item->get_summary();
104
105 if ( ! $summary ) {
106 return null;
107 }
108
109 return array(
110 $this->get_locale() => $summary,
111 );
112 }
113
114 /**
115 * Returns a list of Tags, used in the Comment.
116 *
117 * This includes Hash-Tags and Mentions.
118 *
119 * @return array The list of Tags.
120 */
121 protected function get_tag() {
122 $tags = $this->item->get_tag();
123
124 if ( ! $tags ) {
125 $tags = array();
126 }
127
128 $mentions = $this->get_mentions();
129
130 if ( $mentions ) {
131 foreach ( $mentions as $mention => $url ) {
132 $tag = array(
133 'type' => 'Mention',
134 'href' => \esc_url( $url ),
135 'name' => \esc_html( $mention ),
136 );
137 $tags[] = $tag;
138 }
139 }
140
141 return \array_unique( $tags, SORT_REGULAR );
142 }
143 }
144