PluginProbe
ActivityPub / 3.2.2
ActivityPub v3.2.2
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
← All changes | includes/model/class-application.php +44 -105 9.0.23.2.2 View file →
@@ -1,24 +1,14 @@
1 1 <?php
2 -/**
3 - * Application model file.
4 - *
5 - * @package Activitypub
6 - */
7 -
8 2 namespace Activitypub\Model;
9 3
4 +use WP_Query;
5 +use Activitypub\Signature;
10 6 use Activitypub\Activity\Actor;
11 -use Activitypub\Collection\Actors;
7 +use Activitypub\Collection\Users;
12 8
13 9 use function Activitypub\get_rest_url_by_path;
14 -use function Activitypub\home_host;
15 10
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 11 class Application extends Actor {
22 12 /**
23 13 * The User-ID
24 14 *
@@ -23,90 +13,45 @@
23 13 * The User-ID
24 14 *
25 15 * @var int
26 16 */
27 - protected $_id = Actors::APPLICATION_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
17 + protected $_id = Users::APPLICATION_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
28 18
29 19 /**
30 - * Whether the Application is discoverable.
20 + * If the User is discoverable.
31 21 *
32 22 * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
33 23 *
34 24 * @context http://joinmastodon.org/ns#discoverable
35 25 *
36 - * @var bool
26 + * @var boolean
37 27 */
38 28 protected $discoverable = false;
39 29
40 30 /**
41 - * Whether the Application is indexable.
31 + * If the User is indexable.
42 32 *
43 33 * @context http://joinmastodon.org/ns#indexable
44 34 *
45 - * @var bool
35 + * @var boolean
46 36 */
47 37 protected $indexable = false;
48 38
49 39 /**
50 - * Whether the Application manually approves followers.
40 + * The WebFinger Resource.
51 41 *
52 - * @see https://docs.joinmastodon.org/spec/activitypub/#as
53 - *
54 - * @context as:manuallyApprovesFollowers
55 - *
56 - * @var bool
42 + * @var string<url>
57 43 */
58 - protected $manually_approves_followers = true;
44 + protected $webfinger;
59 45
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 - );
46 + public function get_type() {
47 + return 'Application';
48 + }
73 49
74 - /**
75 - * Set Application as invisible.
76 - *
77 - * @see https://litepub.social/
78 - *
79 - * @var bool
80 - */
81 - protected $invisible = true;
50 + public function get_manually_approves_followers() {
51 + return true;
52 + }
82 53
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 54 public function get_id() {
110 55 return get_rest_url_by_path( 'application' );
111 56 }
112 57
@@ -124,21 +69,29 @@
124 69 *
125 70 * @return string The User-URL with @-Prefix for the username.
126 71 */
127 72 public function get_alternate_url() {
128 - return $this->get_id();
73 + return $this->get_url();
129 74 }
130 75
131 - /**
76 + public function get_name() {
77 + return 'application';
78 + }
79 +
80 + public function get_preferred_username() {
81 + return $this->get_name();
82 + }
83 +
84 + /**
132 85 * Get the User-Icon.
133 86 *
134 - * @return string[] The User-Icon.
87 + * @return array The User-Icon.
135 88 */
136 89 public function get_icon() {
137 - // Try site icon first.
90 + // try site icon first
138 91 $icon_id = get_option( 'site_icon' );
139 92
140 - // Try custom logo second.
93 + // try custom logo second
141 94 if ( ! $icon_id ) {
142 95 $icon_id = get_theme_mod( 'custom_logo' );
143 96 }
144 97
@@ -151,9 +104,9 @@
151 104 }
152 105 }
153 106
154 107 if ( ! $icon_url ) {
155 - // Fallback to default icon.
108 + // fallback to default icon
156 109 $icon_url = plugins_url( '/assets/img/wp-logo.png', ACTIVITYPUB_PLUGIN_FILE );
157 110 }
158 111
159 112 return array(
@@ -164,9 +117,9 @@
164 117
165 118 /**
166 119 * Get the User-Header-Image.
167 120 *
168 - * @return string[]|null The User-Header-Image.
121 + * @return array|null The User-Header-Image.
169 122 */
170 123 public function get_header_image() {
171 124 if ( \has_header_image() ) {
172 125 return array(
@@ -177,15 +130,10 @@
177 130
178 131 return null;
179 132 }
180 133
181 - /**
182 - * Get the first published date.
183 - *
184 - * @return string The published date.
185 - */
186 134 public function get_published() {
187 - $first_post = new \WP_Query(
135 + $first_post = new WP_Query(
188 136 array(
189 137 'orderby' => 'date',
190 138 'order' => 'ASC',
191 139 'number' => 1,
@@ -197,9 +145,9 @@
197 145 } else {
198 146 $time = \time();
199 147 }
200 148
201 - return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $time );
149 + return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
202 150 }
203 151
204 152 /**
205 153 * Returns the Inbox-API-Endpoint.
@@ -227,39 +175,30 @@
227 175 public function get_webfinger() {
228 176 return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
229 177 }
230 178
231 - /**
232 - * Returns the public key.
233 - *
234 - * @return string[] The public key.
235 - */
236 179 public function get_public_key() {
237 180 return array(
238 - 'id' => $this->get_id() . '#main-key',
239 - 'owner' => $this->get_id(),
240 - 'publicKeyPem' => Actors::get_public_key( Actors::APPLICATION_USER_ID ),
181 + 'id' => $this->get_id() . '#main-key',
182 + 'owner' => $this->get_id(),
183 + 'publicKeyPem' => Signature::get_public_key_for( Users::APPLICATION_USER_ID ),
241 184 );
242 185 }
243 186
244 187 /**
245 - * Get the User description.
188 + * Get the User-Description.
246 189 *
247 - * @return string The User description.
190 + * @return string The User-Description.
248 191 */
249 192 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()
193 + return \wpautop(
194 + \wp_kses(
195 + \get_bloginfo( 'description' ),
196 + 'default'
197 + )
254 198 );
255 199 }
256 200
257 - /**
258 - * Returns the canonical URL of the object.
259 - *
260 - * @return string|null The canonical URL of the object.
261 - */
262 201 public function get_canonical_url() {
263 202 return \home_url();
264 203 }
265 204 }