PluginProbe
ActivityPub / 8.3.0
ActivityPub v8.3.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 8.3.0, at includes/model/class-application.php

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