PluginProbe
ActivityPub / 9.2.1
ActivityPub v9.2.1
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 9.2.1, at includes/transformer/class-activity-object.php

158 lines 3.0 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 * The Activity Object.
16 *
17 * @var \Activitypub\Activity\Activity
18 */
19 protected $item;
20
21 /**
22 * Transform the WordPress Object into an ActivityPub Object.
23 *
24 * @return \Activitypub\Activity\Base_Object|\WP_Error
25 */
26 public function to_object() {
27 $activity_object = $this->transform_object_properties( $this->item );
28
29 if ( \is_wp_error( $activity_object ) ) {
30 return $activity_object;
31 }
32
33 return $this->set_audience( $activity_object );
34 }
35
36 /**
37 * Get the ID of the object.
38 *
39 * @return string The ID of the object.
40 */
41 public function get_id() {
42 return $this->item->get_id();
43 }
44
45 /**
46 * Get the attributed to.
47 *
48 * @return string The attributed to.
49 */
50 public function get_attributed_to() {
51 return $this->item->get_attributed_to();
52 }
53
54 /**
55 * Helper function to get the @-Mentions from the post content.
56 *
57 * @return array The list of @-Mentions.
58 */
59 protected function get_mentions() {
60 /**
61 * Filter the mentions in the post content.
62 *
63 * @param array $mentions The mentions.
64 * @param string $content The post content.
65 * @param \Activitypub\Activity\Activity $item The Activity object.
66 *
67 * @return array The filtered mentions.
68 */
69 return \apply_filters(
70 'activitypub_extract_mentions',
71 array(),
72 $this->item->get_content() . ' ' . $this->item->get_summary(),
73 $this->item
74 );
75 }
76
77 /**
78 * Returns the content map for the post.
79 *
80 * @return array The content map for the post.
81 */
82 protected function get_content_map() {
83 $content = $this->item->get_content();
84
85 if ( ! $content ) {
86 return null;
87 }
88
89 return array(
90 $this->get_locale() => $content,
91 );
92 }
93
94 /**
95 * Returns the name map for the post.
96 *
97 * @return array The name map for the post.
98 */
99 protected function get_name_map() {
100 $name = $this->item->get_name();
101
102 if ( ! $name ) {
103 return null;
104 }
105
106 return array(
107 $this->get_locale() => $name,
108 );
109 }
110
111 /**
112 * Returns the summary map for the post.
113 *
114 * @return array The summary map for the post.
115 */
116 protected function get_summary_map() {
117 $summary = $this->item->get_summary();
118
119 if ( ! $summary ) {
120 return null;
121 }
122
123 return array(
124 $this->get_locale() => $summary,
125 );
126 }
127
128 /**
129 * Returns a list of Tags, used in the Comment.
130 *
131 * This includes Hash-Tags and Mentions.
132 *
133 * @return array The list of Tags.
134 */
135 protected function get_tag() {
136 $tags = $this->item->get_tag();
137
138 if ( ! $tags ) {
139 $tags = array();
140 }
141
142 $mentions = $this->get_mentions();
143
144 if ( $mentions ) {
145 foreach ( $mentions as $mention => $url ) {
146 $tag = array(
147 'type' => 'Mention',
148 'href' => \esc_url_raw( $url ),
149 'name' => \esc_html( $mention ),
150 );
151 $tags[] = $tag;
152 }
153 }
154
155 return \array_unique( $tags, SORT_REGULAR );
156 }
157 }
158