PluginProbe
ActivityPub / 7.2.0
ActivityPub v7.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 7.2.0, at includes/model/class-application.php

261 lines 5.1 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 Activitypub\Activity\Actor;
11 use Activitypub\Collection\Actors;
12
13 use function Activitypub\get_rest_url_by_path;
14
15 /**
16 * Application class.
17 *
18 * @method int get__id() Gets the internal user ID for the application (always returns APPLICATION_USER_ID).
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 * List of software capabilities implemented by the Application.
50 *
51 * @see https://codeberg.org/silverpill/feps/src/branch/main/844e/fep-844e.md
52 *
53 * @var array
54 */
55 protected $implements = array(
56 array(
57 'href' => 'https://datatracker.ietf.org/doc/html/rfc9421',
58 'name' => 'RFC-9421: HTTP Message Signatures',
59 ),
60 );
61
62 /**
63 * Returns the type of the object.
64 *
65 * @return string The type of the object.
66 */
67 public function get_type() {
68 return 'Application';
69 }
70
71 /**
72 * Returns whether the Application manually approves followers.
73 *
74 * @return true Whether the Application manually approves followers.
75 */
76 public function get_manually_approves_followers() {
77 return true;
78 }
79
80 /**
81 * Returns the ID of the Application.
82 *
83 * @return string The ID of the Application.
84 */
85 public function get_id() {
86 return get_rest_url_by_path( 'application' );
87 }
88
89 /**
90 * Get the User-Url.
91 *
92 * @return string The User-Url.
93 */
94 public function get_url() {
95 return $this->get_id();
96 }
97
98 /**
99 * Returns the User-URL with @-Prefix for the username.
100 *
101 * @return string The User-URL with @-Prefix for the username.
102 */
103 public function get_alternate_url() {
104 return $this->get_id();
105 }
106
107 /**
108 * Get the Username.
109 *
110 * @return string The Username.
111 */
112 public function get_name() {
113 return 'application';
114 }
115
116 /**
117 * Get the preferred username.
118 *
119 * @return string The preferred username.
120 */
121 public function get_preferred_username() {
122 return $this->get_name();
123 }
124
125 /**
126 * Get the User-Icon.
127 *
128 * @return string[] The User-Icon.
129 */
130 public function get_icon() {
131 // Try site icon first.
132 $icon_id = get_option( 'site_icon' );
133
134 // Try custom logo second.
135 if ( ! $icon_id ) {
136 $icon_id = get_theme_mod( 'custom_logo' );
137 }
138
139 $icon_url = false;
140
141 if ( $icon_id ) {
142 $icon = wp_get_attachment_image_src( $icon_id, 'full' );
143 if ( $icon ) {
144 $icon_url = $icon[0];
145 }
146 }
147
148 if ( ! $icon_url ) {
149 // Fallback to default icon.
150 $icon_url = plugins_url( '/assets/img/wp-logo.png', ACTIVITYPUB_PLUGIN_FILE );
151 }
152
153 return array(
154 'type' => 'Image',
155 'url' => esc_url( $icon_url ),
156 );
157 }
158
159 /**
160 * Get the User-Header-Image.
161 *
162 * @return string[]|null The User-Header-Image.
163 */
164 public function get_header_image() {
165 if ( \has_header_image() ) {
166 return array(
167 'type' => 'Image',
168 'url' => esc_url( \get_header_image() ),
169 );
170 }
171
172 return null;
173 }
174
175 /**
176 * Get the first published date.
177 *
178 * @return string The published date.
179 */
180 public function get_published() {
181 $first_post = new \WP_Query(
182 array(
183 'orderby' => 'date',
184 'order' => 'ASC',
185 'number' => 1,
186 )
187 );
188
189 if ( ! empty( $first_post->posts[0] ) ) {
190 $time = \strtotime( $first_post->posts[0]->post_date_gmt );
191 } else {
192 $time = \time();
193 }
194
195 return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $time );
196 }
197
198 /**
199 * Returns the Inbox-API-Endpoint.
200 *
201 * @return string The Inbox-Endpoint.
202 */
203 public function get_inbox() {
204 return get_rest_url_by_path( sprintf( 'actors/%d/inbox', $this->get__id() ) );
205 }
206
207 /**
208 * Returns the Outbox-API-Endpoint.
209 *
210 * @return string The Outbox-Endpoint.
211 */
212 public function get_outbox() {
213 return get_rest_url_by_path( sprintf( 'actors/%d/outbox', $this->get__id() ) );
214 }
215
216 /**
217 * Returns a user@domain type of identifier for the user.
218 *
219 * @return string The Webfinger-Identifier.
220 */
221 public function get_webfinger() {
222 return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
223 }
224
225 /**
226 * Returns the public key.
227 *
228 * @return string[] The public key.
229 */
230 public function get_public_key() {
231 return array(
232 'id' => $this->get_id() . '#main-key',
233 'owner' => $this->get_id(),
234 'publicKeyPem' => Actors::get_public_key( Actors::APPLICATION_USER_ID ),
235 );
236 }
237
238 /**
239 * Get the User description.
240 *
241 * @return string The User description.
242 */
243 public function get_summary() {
244 return \wpautop(
245 \wp_kses(
246 \get_bloginfo( 'description' ),
247 'default'
248 )
249 );
250 }
251
252 /**
253 * Returns the canonical URL of the object.
254 *
255 * @return string|null The canonical URL of the object.
256 */
257 public function get_canonical_url() {
258 return \home_url();
259 }
260 }
261