| @@ -1,11 +1,8 @@ | ||
| 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; |
| @@ -10,9 +7,9 @@ | ||
| 10 | 7 | |
| 11 | 8 | namespace Activitypub\Model; |
| 12 | 9 | |
| 13 | 10 | use Activitypub\Activity\Actor; |
| 14 | -use Activitypub\Application as Application_Utility; | |
| 11 | +use Activitypub\Collection\Actors; | |
| 15 | 12 | |
| 16 | 13 | use function Activitypub\get_rest_url_by_path; |
| 17 | 14 | use function Activitypub\home_host; |
| 18 | 15 | |
| @@ -18,9 +15,9 @@ | ||
| 18 | 15 | |
| 19 | 16 | /** |
| 20 | 17 | * Application class. |
| 21 | 18 | * |
| 22 | - * @deprecated Use {@see \Activitypub\Application} instead. | |
| 19 | + * @method int get__id() Gets the internal user ID for the application (always returns APPLICATION_USER_ID). | |
| 23 | 20 | */ |
| 24 | 21 | class Application extends Actor { |
| 25 | 22 | /** |
| 26 | 23 | * The User-ID |
| @@ -26,9 +23,9 @@ | ||
| 26 | 23 | * The User-ID |
| 27 | 24 | * |
| 28 | 25 | * @var int |
| 29 | 26 | */ |
| 30 | - protected $_id = -1; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore | |
| 27 | + protected $_id = Actors::APPLICATION_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore | |
| 31 | 28 | |
| 32 | 29 | /** |
| 33 | 30 | * Whether the Application is discoverable. |
| 34 | 31 | * |
| @@ -104,21 +101,14 @@ | ||
| 104 | 101 | */ |
| 105 | 102 | protected $preferred_username = 'application'; |
| 106 | 103 | |
| 107 | 104 | /** |
| 108 | - * Constructor. | |
| 109 | - */ | |
| 110 | - public function __construct() { | |
| 111 | - \_deprecated_class( __CLASS__, '9.1.0', 'Activitypub\Application' ); | |
| 112 | - } | |
| 113 | - | |
| 114 | - /** | |
| 115 | 105 | * Returns the ID of the Application. |
| 116 | 106 | * |
| 117 | 107 | * @return string The ID of the Application. |
| 118 | 108 | */ |
| 119 | 109 | public function get_id() { |
| 120 | - return Application_Utility::get_id(); | |
| 110 | + return get_rest_url_by_path( 'application' ); | |
| 121 | 111 | } |
| 122 | 112 | |
| 123 | 113 | /** |
| 124 | 114 | * Get the User-Url. |
| @@ -143,9 +133,34 @@ | ||
| 143 | 133 | * |
| 144 | 134 | * @return string[] The User-Icon. |
| 145 | 135 | */ |
| 146 | 136 | public function get_icon() { |
| 147 | - return Application_Utility::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 | + ); | |
| 148 | 163 | } |
| 149 | 164 | |
| 150 | 165 | /** |
| 151 | 166 | * Get the User-Header-Image. |
| @@ -155,9 +170,9 @@ | ||
| 155 | 170 | public function get_header_image() { |
| 156 | 171 | if ( \has_header_image() ) { |
| 157 | 172 | return array( |
| 158 | 173 | 'type' => 'Image', |
| 159 | - 'url' => \esc_url_raw( \get_header_image() ), | |
| 174 | + 'url' => esc_url( \get_header_image() ), | |
| 160 | 175 | ); |
| 161 | 176 | } |
| 162 | 177 | |
| 163 | 178 | return null; |
| @@ -168,9 +183,23 @@ | ||
| 168 | 183 | * |
| 169 | 184 | * @return string The published date. |
| 170 | 185 | */ |
| 171 | 186 | public function get_published() { |
| 172 | - return Application_Utility::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 ); | |
| 173 | 202 | } |
| 174 | 203 | |
| 175 | 204 | /** |
| 176 | 205 | * Returns the Inbox-API-Endpoint. |
| @@ -177,9 +206,9 @@ | ||
| 177 | 206 | * |
| 178 | 207 | * @return string The Inbox-Endpoint. |
| 179 | 208 | */ |
| 180 | 209 | public function get_inbox() { |
| 181 | - return get_rest_url_by_path( 'inbox' ); | |
| 210 | + return get_rest_url_by_path( sprintf( 'actors/%d/inbox', $this->get__id() ) ); | |
| 182 | 211 | } |
| 183 | 212 | |
| 184 | 213 | /** |
| 185 | 214 | * Returns the Outbox-API-Endpoint. |
| @@ -186,9 +215,9 @@ | ||
| 186 | 215 | * |
| 187 | 216 | * @return string The Outbox-Endpoint. |
| 188 | 217 | */ |
| 189 | 218 | public function get_outbox() { |
| 190 | - return get_rest_url_by_path( 'application/outbox' ); | |
| 219 | + return get_rest_url_by_path( sprintf( 'actors/%d/outbox', $this->get__id() ) ); | |
| 191 | 220 | } |
| 192 | 221 | |
| 193 | 222 | /** |
| 194 | 223 | * Returns a user@domain type of identifier for the user. |
| @@ -205,11 +234,11 @@ | ||
| 205 | 234 | * @return string[] The public key. |
| 206 | 235 | */ |
| 207 | 236 | public function get_public_key() { |
| 208 | 237 | return array( |
| 209 | - 'id' => Application_Utility::get_key_id(), | |
| 238 | + 'id' => $this->get_id() . '#main-key', | |
| 210 | 239 | 'owner' => $this->get_id(), |
| 211 | - 'publicKeyPem' => Application_Utility::get_public_key(), | |
| 240 | + 'publicKeyPem' => Actors::get_public_key( Actors::APPLICATION_USER_ID ), | |
| 212 | 241 | ); |
| 213 | 242 | } |
| 214 | 243 | |
| 215 | 244 | /** |
| @@ -217,11 +246,11 @@ | ||
| 217 | 246 | * |
| 218 | 247 | * @return string The User description. |
| 219 | 248 | */ |
| 220 | 249 | public function get_summary() { |
| 221 | - return \sprintf( | |
| 250 | + return sprintf( | |
| 222 | 251 | /* translators: %s: Domain of the site */ |
| 223 | - \__( 'This is the Application Actor for %s.', 'activitypub' ), | |
| 252 | + __( 'This is the Application Actor for %s.', 'activitypub' ), | |
| 224 | 253 | home_host() |
| 225 | 254 | ); |
| 226 | 255 | } |
| 227 | 256 | |