PluginProbe
ActivityPub / 4.2.0
ActivityPub v4.2.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 / model / class-application.php

class-application.php in ActivityPub 4.2.0, at includes/model/class-application.php

254 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Application model file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\Model;
9
10 use WP_Query;
11 use Activitypub\Signature;
12 use Activitypub\Activity\Actor;
13 use Activitypub\Collection\Actors;
14
15 use function Activitypub\get_rest_url_by_path;
16
17 /**
18 * Application class.
19 */
20 class Application extends Actor {
21 /**
22 * The User-ID
23 *
24 * @var int
25 */
26 protected $_id = Actors::APPLICATION_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
27
28 /**
29 * Whether the Application is discoverable.
30 *
31 * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
32 *
33 * @context http://joinmastodon.org/ns#discoverable
34 *
35 * @var boolean
36 */
37 protected $discoverable = false;
38
39 /**
40 * Whether the Application is indexable.
41 *
42 * @context http://joinmastodon.org/ns#indexable
43 *
44 * @var boolean
45 */
46 protected $indexable = false;
47
48 /**
49 * The WebFinger Resource.
50 *
51 * @var string
52 */
53 protected $webfinger;
54
55 /**
56 * Returns the type of the object.
57 *
58 * @return string The type of the object.
59 */
60 public function get_type() {
61 return 'Application';
62 }
63
64 /**
65 * Returns whether the Application manually approves followers.
66 *
67 * @return true Whether the Application manually approves followers.
68 */
69 public function get_manually_approves_followers() {
70 return true;
71 }
72
73 /**
74 * Returns the ID of the Application.
75 *
76 * @return string The ID of the Application.
77 */
78 public function get_id() {
79 return get_rest_url_by_path( 'application' );
80 }
81
82 /**
83 * Get the User-Url.
84 *
85 * @return string The User-Url.
86 */
87 public function get_url() {
88 return $this->get_id();
89 }
90
91 /**
92 * Returns the User-URL with @-Prefix for the username.
93 *
94 * @return string The User-URL with @-Prefix for the username.
95 */
96 public function get_alternate_url() {
97 return $this->get_id();
98 }
99
100 /**
101 * Get the Username.
102 *
103 * @return string The Username.
104 */
105 public function get_name() {
106 return 'application';
107 }
108
109 /**
110 * Get the preferred username.
111 *
112 * @return string The preferred username.
113 */
114 public function get_preferred_username() {
115 return $this->get_name();
116 }
117
118 /**
119 * Get the User-Icon.
120 *
121 * @return array The User-Icon.
122 */
123 public function get_icon() {
124 // Try site icon first.
125 $icon_id = get_option( 'site_icon' );
126
127 // Try custom logo second.
128 if ( ! $icon_id ) {
129 $icon_id = get_theme_mod( 'custom_logo' );
130 }
131
132 $icon_url = false;
133
134 if ( $icon_id ) {
135 $icon = wp_get_attachment_image_src( $icon_id, 'full' );
136 if ( $icon ) {
137 $icon_url = $icon[0];
138 }
139 }
140
141 if ( ! $icon_url ) {
142 // Fallback to default icon.
143 $icon_url = plugins_url( '/assets/img/wp-logo.png', ACTIVITYPUB_PLUGIN_FILE );
144 }
145
146 return array(
147 'type' => 'Image',
148 'url' => esc_url( $icon_url ),
149 );
150 }
151
152 /**
153 * Get the User-Header-Image.
154 *
155 * @return array|null The User-Header-Image.
156 */
157 public function get_header_image() {
158 if ( \has_header_image() ) {
159 return array(
160 'type' => 'Image',
161 'url' => esc_url( \get_header_image() ),
162 );
163 }
164
165 return null;
166 }
167
168 /**
169 * Get the first published date.
170 *
171 * @return string The published date.
172 */
173 public function get_published() {
174 $first_post = new WP_Query(
175 array(
176 'orderby' => 'date',
177 'order' => 'ASC',
178 'number' => 1,
179 )
180 );
181
182 if ( ! empty( $first_post->posts[0] ) ) {
183 $time = \strtotime( $first_post->posts[0]->post_date_gmt );
184 } else {
185 $time = \time();
186 }
187
188 return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
189 }
190
191 /**
192 * Returns the Inbox-API-Endpoint.
193 *
194 * @return string The Inbox-Endpoint.
195 */
196 public function get_inbox() {
197 return get_rest_url_by_path( sprintf( 'actors/%d/inbox', $this->get__id() ) );
198 }
199
200 /**
201 * Returns the Outbox-API-Endpoint.
202 *
203 * @return string The Outbox-Endpoint.
204 */
205 public function get_outbox() {
206 return get_rest_url_by_path( sprintf( 'actors/%d/outbox', $this->get__id() ) );
207 }
208
209 /**
210 * Returns a user@domain type of identifier for the user.
211 *
212 * @return string The Webfinger-Identifier.
213 */
214 public function get_webfinger() {
215 return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
216 }
217
218 /**
219 * Returns the public key.
220 *
221 * @return array The public key.
222 */
223 public function get_public_key() {
224 return array(
225 'id' => $this->get_id() . '#main-key',
226 'owner' => $this->get_id(),
227 'publicKeyPem' => Signature::get_public_key_for( Actors::APPLICATION_USER_ID ),
228 );
229 }
230
231 /**
232 * Get the User description.
233 *
234 * @return string The User description.
235 */
236 public function get_summary() {
237 return \wpautop(
238 \wp_kses(
239 \get_bloginfo( 'description' ),
240 'default'
241 )
242 );
243 }
244
245 /**
246 * Returns the canonical URL of the object.
247 *
248 * @return string|null The canonical URL of the object.
249 */
250 public function get_canonical_url() {
251 return \home_url();
252 }
253 }
254