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