PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.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.7.0, at includes/transformer/class-activity-object.php

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