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