Changeset 3248503
- Timestamp:
- 02/28/2025 12:49:05 PM (10 days ago)
- Location:
- enable-mastodon-apps/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
enable-mastodon-apps/trunk/README.md
r3245135 r3248503 7 7 - Requires PHP: 7.4 8 8 - License: [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) 9 - Stable tag: 1. 2.19 - Stable tag: 1.3.0 10 10 11 11 Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance. … … 101 101 ## Changelog 102 102 103 ### 1.3.0 104 - Fix small errors on app page ([#224]) 105 - Show internal CPTs if debug is turned on ([#223]) 106 - Add setting for a default post format ([#221]) 107 - Improve New Post Setting and explicit set a New post format ([#220], [#222]) 108 - Assign all post formats to EMA announcements ([#218]) 109 103 110 ### 1.2.1 104 111 - Fixed Boost, Like and Comment notifications ([#216]) … … 181 188 - Fix OAuth rewrite path ([#130]) 182 189 190 [#224]: https://github.com/akirk/enable-mastodon-apps/pull/224 191 [#223]: https://github.com/akirk/enable-mastodon-apps/pull/223 192 [#222]: https://github.com/akirk/enable-mastodon-apps/pull/222 193 [#221]: https://github.com/akirk/enable-mastodon-apps/pull/221 194 [#220]: https://github.com/akirk/enable-mastodon-apps/pull/220 195 [#218]: https://github.com/akirk/enable-mastodon-apps/pull/218 183 196 [#216]: https://github.com/akirk/enable-mastodon-apps/pull/216 184 197 [#214]: https://github.com/akirk/enable-mastodon-apps/pull/214 -
enable-mastodon-apps/trunk/enable-mastodon-apps.php
r3245135 r3248503 4 4 * Plugin author: Alex Kirk 5 5 * Plugin URI: https://github.com/akirk/enable-mastodon-apps 6 * Version: 1. 2.16 * Version: 1.3.0 7 7 * 8 8 * Description: Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance. … … 21 21 define( 'ENABLE_MASTODON_APPS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 22 22 define( 'ENABLE_MASTODON_APPS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 23 define( 'ENABLE_MASTODON_APPS_VERSION', '1. 2.1' );23 define( 'ENABLE_MASTODON_APPS_VERSION', '1.3.0' ); 24 24 25 25 require __DIR__ . '/vendor/bshaffer/oauth2-server-php/src/OAuth2/Autoloader.php'; -
enable-mastodon-apps/trunk/includes/class-mastodon-admin.php
r3245133 r3248503 57 57 'title' => __( 'Settings' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain 58 58 'content' => 59 '< p><strong>' . esc_html__( 'Hide posts through Mastodon apps from appearing on the WordPress frontend', 'enable-mastodon-apps' ) . '</strong><br>' .60 '<span>' . esc_html__( 'Setting this depends on your use case:', 'enable-mastodon-apps' ) . '</span>' . 59 '<ul><li><strong>' . esc_html__( 'Hide posts through Mastodon apps from appearing on the WordPress frontend', 'enable-mastodon-apps' ) . '</strong>' . 60 61 61 '<ul>' . 62 '<li>' . esc_html__( 'If you want to use Mastodon apps to read just the posts on your site (for example in a blog with many authors, and you are interested in what the other authors post), and post to the site directly, uncheck the box.', 'enable-mastodon-apps' ) . '</li>' . 63 '<li>' . 62 '<li><span>' . 63 __( 'Check this if you want keep your use of Mastodon separate from your activity on your site.', 'enable-mastodon-apps' ) . '</span> <span>' . 64 __( 'Posting through a Mastodon app would still save the post in your WordPress but invisibly to visitors and subscribers of your WordPress.', 'enable-mastodon-apps' ) . '</span> <span>' . 64 65 wp_kses( 65 66 sprintf( 66 // translators: Links to the plugins. 67 __( 'If you want to use Mastodon apps to post to Mastodon (when combining with the <a href="%1$s">Friends plugin</a> and <a href="%2$s">ActivityPub plugin</a>) but want to avoid posting it visibly to your site (which for example would be sent to your subscribers), leave it checked.', 'enable-mastodon-apps' ), 68 'https://wordpress.org/plugins/friends/" target="_blank', 67 // translators: Links to the plugin. 68 __( 'Remember that for posting to Mastodon, you\'ll need the <a href="%s">ActivityPub plugin</a>.', 'enable-mastodon-apps' ), 69 69 'https://wordpress.org/plugins/activitypub/" target="_blank' 70 70 ), 71 71 array( 72 'a' => array( 73 'href' => true, 74 'target' => true, 72 'a' => array( 73 'href' => true, 74 'target' => true, 75 ), 76 ) 77 ) . '</span> <span>' . 78 wp_kses( 79 sprintf( 80 // translators: Links to the plugin. 81 __( 'If you also want to follow people and interact with them, please also install the <a href="%s">Friends plugin</a>.', 'enable-mastodon-apps' ), 82 'https://wordpress.org/plugins/friends/" target="_blank' 75 83 ), 84 array( 85 'a' => array( 86 'href' => true, 87 'target' => true, 88 ), 76 89 ) 77 90 ) . 78 '</li>' . 79 '<li>' . 91 '</span></li>' . 92 // translators: %s: a post type name. 93 '<li>' . wp_kses( sprintf( __( 'With this setting, newly registered apps will be configured to save new posts as %s.', 'enable-mastodon-apps' ), '<tt>' . $ema_post_cpt->labels->singular_name . '</tt>' ), array( 'tt' => true ) ) . '</span> <span>' . 94 // translators: %s: a post type name. 95 wp_kses( sprintf( __( 'You can see and edit these posts in the sidebar menu of WP Admin under %s.', 'enable-mastodon-apps' ), '<a href="' . self_admin_url( 'edit.php?post_type=' . $ema_post_cpt->name ) . '">' . $ema_post_cpt->labels->name . '</a>' ), array( 'a' => array( 'href' => true ) ) ) . '</span> <span>' . 96 esc_html__( 'This setting can be changed individually per app in its individual settings page.', 'enable-mastodon-apps' ) . '</span></li>' . 97 '</ul>' . 98 '<li><strong>' . esc_html__( 'Show posts through Mastodon apps on the WordPress frontend', 'enable-mastodon-apps' ) . '</strong>' . 99 '<ul>' . 100 '<li>' . esc_html__( 'Check this if you want to use Mastodon apps to post to the site directly.', 'enable-mastodon-apps' ) . '</span> <span>' . 101 // translators: %s: a post format name. 102 wp_kses( sprintf( __( 'Your posts will appear in your RSS feed and be sent to your subscribers unless you specify a post format, for example %s.', 'enable-mastodon-apps' ), '<tt>' . _x( 'Status', 'Post format' ) . '</tt>' ), array( 'tt' => true ) ) . '</span> <span>' . // phpcs:ignore WordPress.WP.I18n.MissingArgDomain 103 esc_html__( 'That way, those posts will only appear in the specific RSS feed, and are typically not sent to subcribers.', 'enable-mastodon-apps' ) . '</span> <span>' . 80 104 wp_kses( 81 105 sprintf( 82 // translators: Links to the plugin s.83 __( ' If you do want to expose such posts also on your site (for example in a <a href="%s">POSSE</a> use case), uncheck the box.', 'enable-mastodon-apps' ),84 'https:// indieweb.org/POSSE" target="_blank'106 // translators: Links to the plugin. 107 __( 'Like above, if you combine it with the <a href="%s">ActivityPub plugin</a>, people on Mastodon will be able to read your posts.', 'enable-mastodon-apps' ), 108 'https://wordpress.org/plugins/activitypub/" target="_blank' 85 109 ), 86 110 array( 87 'a' => array( 88 'href' => true, 89 'target' => true, 111 'a' => array( 112 'href' => true, 113 'target' => true, 114 ), 115 ) 116 ) . '</span> <span>' . 117 wp_kses( 118 sprintf( 119 // translators: Links to the plugin. 120 __( 'Also, with the <a href="%s">Friends plugin</a>, you will be able to follow people and interact with them', 'enable-mastodon-apps' ), 121 'https://wordpress.org/plugins/friends/" target="_blank' 90 122 ), 123 array( 124 'a' => array( 125 'href' => true, 126 'target' => true, 127 ), 91 128 ) 92 129 ) . 93 '</li>' . 94 '</ul>' . 95 '<span>' . 96 wp_kses( 97 sprintf( 98 // translators: %1$s and %2$s: a post type. 99 __( 'When checked, new posts made through Mastodon apps will have the post type %1$s, otherwise %2$s when unchecked.', 'enable-mastodon-apps' ), 100 '<strong>' . $ema_post_cpt->labels->singular_name . '</strong>', 101 '<strong>' . $post_cpt->labels->singular_name . '</strong>' 102 ), 103 array( 'strong' => true ) 104 ) . 105 '</span>' . 106 '</p>', 130 // translators: %s: a post type name. 131 '<li>' . wp_kses( sprintf( __( 'With this setting, newly registered apps will be configured to save new posts as %s.', 'enable-mastodon-apps' ), '<tt>' . $post_cpt->labels->singular_name . '</tt>' ), array( 'tt' => true ) ) . 132 '</span> <span>' . esc_html__( 'This setting can be changed individually per app in its individual settings page.', 'enable-mastodon-apps' ) . '</span></li>' . 133 '</ul>', 107 134 ) 108 135 ); … … 130 157 if ( isset( $_POST['app'] ) ) { 131 158 $app = Mastodon_App::get_by_client_id( sanitize_text_field( wp_unslash( $_POST['app'] ) ) ); 132 if ( $app ) {159 if ( $app && ! is_wp_error( $app ) ) { 133 160 return $this->process_admin_app_page( $app ); 134 161 } … … 156 183 if ( isset( $_GET['app'] ) ) { 157 184 $app = Mastodon_App::get_by_client_id( sanitize_text_field( wp_unslash( $_GET['app'] ) ) ); 158 if ( $app ) {185 if ( $app && ! is_wp_error( $app ) ) { 159 186 return $this->admin_app_page( $app ); 160 187 } … … 193 220 194 221 public function process_admin_settings_page() { 195 if ( isset( $_POST['mastodon_api_enable_logins'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing 222 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'enable-mastodon-apps' ) ) { 223 return; 224 } 225 226 if ( isset( $_POST['mastodon_api_enable_logins'] ) ) { 196 227 delete_option( 'mastodon_api_disable_logins' ); 197 228 } else { 198 229 update_option( 'mastodon_api_disable_logins', true ); 230 } 231 232 if ( isset( $_POST['mastodon_api_default_create_post_format'] ) ) { 233 $post_format = sanitize_text_field( wp_unslash( $_POST['mastodon_api_default_create_post_format'] ) ); 234 if ( in_array( $post_format, get_post_format_slugs(), true ) ) { 235 update_option( 'mastodon_api_default_create_post_format', $post_format, false ); 236 } else { 237 delete_option( 'mastodon_api_default_create_post_format' ); 238 } 199 239 } 200 240 … … 215 255 $default_ema_post_type = apply_filters( 'mastodon_api_default_post_type', \Enable_Mastodon_Apps\Mastodon_API::POST_CPT ); 216 256 217 if ( isset( $_POST['mastodon_api_posting_cpt'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing257 if ( isset( $_POST['mastodon_api_posting_cpt'] ) && intval( $_POST['mastodon_api_posting_cpt'] ) === 1 ) { 218 258 delete_option( 'mastodon_api_posting_cpt' ); 219 259 … … 225 265 } 226 266 } 227 } else {267 } elseif ( isset( $_POST['mastodon_api_posting_cpt'] ) && intval( $_POST['mastodon_api_posting_cpt'] ) === 0 ) { 228 268 update_option( 'mastodon_api_posting_cpt', 'post', false ); 229 269 … … 237 277 } 238 278 239 if ( isset( $_POST['mastodon_api_disable_ema_announcements'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing279 if ( isset( $_POST['mastodon_api_disable_ema_announcements'] ) ) { 240 280 delete_option( 'mastodon_api_disable_ema_announcements' ); 241 281 } else { … … 243 283 } 244 284 245 if ( isset( $_POST['mastodon_api_disable_ema_app_settings_changes'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing285 if ( isset( $_POST['mastodon_api_disable_ema_app_settings_changes'] ) ) { 246 286 delete_option( 'mastodon_api_disable_ema_app_settings_changes' ); 247 287 } else { … … 249 289 } 250 290 251 if ( isset( $_POST['mastodon_api_enable_debug'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing291 if ( isset( $_POST['mastodon_api_enable_debug'] ) ) { 252 292 update_option( 'mastodon_api_enable_debug', true ); 253 293 } else { … … 267 307 268 308 public function process_admin_debug_page() { 269 if ( isset( $_POST['mastodon_api_debug_mode'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing 309 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'enable-mastodon-apps' ) ) { 310 return; 311 } 312 313 if ( isset( $_POST['mastodon_api_debug_mode'] ) ) { 270 314 update_option( 'mastodon_api_debug_mode', time() + 5 * MINUTE_IN_SECONDS ); 271 315 } else { 272 316 delete_option( 'mastodon_api_debug_mode' ); 273 317 } 274 if ( isset( $_POST['mastodon_api_auto_app_reregister'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing318 if ( isset( $_POST['mastodon_api_auto_app_reregister'] ) ) { 275 319 update_option( 'mastodon_api_auto_app_reregister', true ); 276 320 } else { … … 288 332 289 333 public function process_admin_registered_apps_page() { 290 // phpcs:ignore WordPress.Security.NonceVerification.Missing 334 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'enable-mastodon-apps' ) ) { 335 return; 336 } 337 291 338 if ( isset( $_POST['delete-code'] ) ) { 292 // phpcs:ignore WordPress.Security.NonceVerification.Missing293 339 $deleted = $this->oauth->get_code_storage()->expireAuthorizationCode( sanitize_text_field( wp_unslash( $_POST['delete-code'] ) ) ); 294 340 add_settings_error( … … 305 351 } 306 352 307 // phpcs:ignore WordPress.Security.NonceVerification.Missing308 353 if ( isset( $_POST['delete-token'] ) ) { 309 // phpcs:ignore WordPress.Security.NonceVerification.Missing 310 $deleted = $this->oauth->get_token_storage()->unsetAccessToken( sanitize_text_field( wp_unslash( $_POST['delete-token'] ) ) ); 354 $deleted = $this->oauth->get_token_storage()->unsetAccessToken( sanitize_text_field( wp_unslash( $_POST['delete-token'] ) ) ); 311 355 add_settings_error( 312 356 'enable-mastodon-apps', … … 322 366 } 323 367 324 // phpcs:ignore WordPress.Security.NonceVerification.Missing325 368 if ( isset( $_POST['delete-app'] ) ) { 326 // phpcs:ignore WordPress.Security.NonceVerification.Missing 327 $deleted = Mastodon_App::get_by_client_id( sanitize_text_field( wp_unslash( $_POST['delete-app'] ) ) )->delete(); 369 $deleted = Mastodon_App::get_by_client_id( sanitize_text_field( wp_unslash( $_POST['delete-app'] ) ) )->delete(); 328 370 add_settings_error( 329 371 'enable-mastodon-apps', … … 339 381 } 340 382 341 // phpcs:ignore WordPress.Security.NonceVerification.Missing342 383 if ( isset( $_POST['clear-app-logs'] ) ) { 343 // phpcs:ignore WordPress.Security.NonceVerification.Missing 344 $deleted = Mastodon_App::get_by_client_id( sanitize_text_field( wp_unslash( $_POST['clear-app-logs'] ) ) )->delete_last_requests(); 384 $deleted = Mastodon_App::get_by_client_id( sanitize_text_field( wp_unslash( $_POST['clear-app-logs'] ) ) )->delete_last_requests(); 345 385 if ( $deleted ) { 346 386 add_settings_error( … … 360 400 return; 361 401 } 362 // phpcs:ignore WordPress.Security.NonceVerification.Missing363 402 if ( isset( $_POST['clear-all-app-logs'] ) ) { 364 403 $total_deleted = 0; … … 391 430 } 392 431 393 // phpcs:ignore WordPress.Security.NonceVerification.Missing394 432 if ( isset( $_POST['delete-outdated'] ) ) { 395 433 $apps = Mastodon_App::get_all(); … … 457 495 } 458 496 459 // phpcs:ignore WordPress.Security.NonceVerification.Missing460 497 if ( isset( $_POST['delete-never-used'] ) ) { 461 498 $deleted = 0; … … 500 537 } 501 538 502 // phpcs:ignore WordPress.Security.NonceVerification.Missing503 539 if ( isset( $_POST['delete-apps-without-tokens'] ) ) { 504 540 $app_tokens = array(); … … 529 565 return; 530 566 } 531 // phpcs:disable WordPress.Security.NonceVerification.Missing 567 532 568 if ( isset( $_POST['app_post_formats'] ) && is_array( $_POST['app_post_formats'] ) ) { 533 569 // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized … … 602 638 603 639 public function process_admin_app_page( Mastodon_App $app ) { 640 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'enable-mastodon-apps' ) ) { 641 return; 642 } 604 643 605 644 if ( isset( $_POST['delete-app'] ) && $_POST['delete-app'] === $app->get_client_id() ) { … … 693 732 } 694 733 734 if ( isset( $_POST['create_post_format'] ) ) { 735 $create_post_format = sanitize_text_field( wp_unslash( $_POST['create_post_format'] ) ); 736 if ( in_array( $create_post_format, $post_formats ) ) { 737 $app->set_create_post_format( $create_post_format ); 738 } else { 739 $app->set_create_post_format( '' ); 740 } 741 } 742 695 743 if ( isset( $_POST['view_post_types'] ) && is_array( $_POST['view_post_types'] ) ) { 696 744 $view_post_types = array( … … 747 795 748 796 if ( ! get_option( 'mastodon_api_disable_ema_announcements' ) ) { 797 $post_id = false; 749 798 if ( ! $old_version ) { 750 799 $title = __( 'Welcome to Enable Mastodon Apps!', 'enable-mastodon-apps' ); … … 779 828 $content .= sprintf( __( 'If you enjoy using this plugin, please let us know at the <a href=%s>EMA WordPress.org plugin page</a>.', 'enable-mastodon-apps' ), '"https://wordpress.org/plugins/enable-mastodon-apps/"' ); 780 829 781 wp_insert_post(830 $post_id = wp_insert_post( 782 831 array( 783 832 'post_type' => Mastodon_API::ANNOUNCE_CPT, … … 788 837 ) 789 838 ); 839 790 840 } else { 791 841 $readme = file_get_contents( ENABLE_MASTODON_APPS_PLUGIN_DIR . 'README.md' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents … … 811 861 $changes = wp_kses( $changes, array( 'a' => array( 'href' => true ) ) ); 812 862 813 wp_insert_post(863 $post_id = wp_insert_post( 814 864 array( 815 865 'post_type' => Mastodon_API::ANNOUNCE_CPT, … … 820 870 ); 821 871 } 872 } 873 if ( $post_id ) { 874 // Assign all post formats so that it will be shown regardless of the app's (potentially later changed) post format settings. 875 wp_set_object_terms( 876 $post_id, 877 array_map( 878 function ( $slug ) { 879 return 'post-format-' . $slug; 880 }, 881 get_post_format_slugs() 882 ), 883 'post_format' 884 ); 822 885 } 823 886 } -
enable-mastodon-apps/trunk/includes/class-mastodon-api.php
r3245133 r3248503 192 192 ), 193 193 'description' => __( 'Posted through a Mastodon app.', 'enable-mastodon-apps' ), 194 'public' => ! get_option( 'mastodon_api_posting_cpt' ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ,194 'public' => ! get_option( 'mastodon_api_posting_cpt' ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || get_option( 'mastodon_api_enable_debug' ), 195 195 'show_in_rest' => false, 196 196 'rewrite' => false, … … 207 207 ), 208 208 'description' => __( 'Announcement by the Enable Mastodon Apps plugin.', 'enable-mastodon-apps' ), 209 'public' => defined( 'WP_DEBUG' ) && WP_DEBUG,209 'public' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || get_option( 'mastodon_api_enable_debug' ), 210 210 'show_in_rest' => false, 211 211 'rewrite' => false, … … 1998 1998 $scheduled_at = $request->get_param( 'scheduled_at' ); 1999 1999 2000 $app = Mastodon_App::get_current_app(); 2001 $app_post_formats = array(); 2002 if ( $app ) { 2003 $app_post_formats = $app->get_post_formats(); 2004 } 2005 if ( empty( $app_post_formats ) ) { 2006 $app_post_formats = array( 'status' ); 2007 } 2008 $post_format = apply_filters( 'mastodon_api_new_post_format', $app_post_formats[0] ); 2009 2000 $app = Mastodon_App::get_current_app(); 2001 $post_format = $app->get_create_post_format(); 2010 2002 $status = apply_filters( 'mastodon_api_submit_status', null, $status_text, $in_reply_to_id, $media_ids, $post_format, $visibility, $scheduled_at, $request ); 2011 2003 … … 2387 2379 $scheduled_at = $request->get_param( 'scheduled_at' ); 2388 2380 2389 $app = Mastodon_App::get_current_app(); 2390 $app_post_formats = array(); 2391 if ( $app ) { 2392 $app_post_formats = $app->get_post_formats(); 2393 } 2394 if ( empty( $app_post_formats ) ) { 2395 $app_post_formats = array( 'status' ); 2396 } 2397 $post_format = apply_filters( 'mastodon_api_new_post_format', $app_post_formats[0] ); 2398 2381 $app = Mastodon_App::get_current_app(); 2382 $post_format = $app->get_create_post_format(); 2399 2383 $status = apply_filters( 'mastodon_api_edit_status', null, $post_id, $status_text, $in_reply_to_id, $media_ids, $post_format, $visibility, $scheduled_at, $request ); 2400 2384 … … 2963 2947 ); 2964 2948 2965 $post_formats = $app->get_post_formats(); 2966 $content[] = sprintf( 2967 // Translators: %s is the post formats. 2968 _n( 'Posts with the post format <strong>%s</strong> will appear in this app.', 'Posts with the post formats <strong>%s</strong> will appear in this app.', count( $app->get_post_formats() ), 'enable-mastodon-apps' ), 2969 implode( ', ', $post_formats ) 2970 ); 2971 2972 $content[] = sprintf( 2973 // Translators: %s is the post format. 2974 __( 'If you create a new note in this app, it will be created with the <strong>%s</strong> post format.', 'enable-mastodon-apps' ), 2975 reset( $post_formats ) 2976 ); 2977 2978 if ( 'standard' === reset( $post_formats ) ) { 2979 $content[] = __( 'If you want to create a post in WordPress with a title, add a new line after the title. The first line will then appear as the title of the post.', 'enable-mastodon-apps' ); 2980 } else { 2981 $content[] = __( 'Because a new post is not created in the standard post format, it will be published without title. To change this, select the <strong>standard</strong> post format in the Enable Mastodon Apps settings.', 'enable-mastodon-apps' ); 2982 } 2949 $content[] = $app->get_current_settings_text( __( 'Settings for this app:', 'enable-mastodon-apps' ) ); 2950 2951 // translators: %s: settings page URL. 2952 $content[] = sprintf( __( 'Change the <a href=%s>settings for this app here</a>.', 'enable-mastodon-apps' ), '"' . esc_url( admin_url( 'options-general.php?page=enable-mastodon-apps&app=' . $app->get_client_id() ) ) . '"' ); 2983 2953 2984 2954 $ret[] = array( -
enable-mastodon-apps/trunk/includes/class-mastodon-app.php
r3245133 r3248503 108 108 } 109 109 110 public function get_create_post_format( $raw = false ) { 111 $create_post_format = get_term_meta( $this->term->term_id, 'create_post_format', true ); 112 if ( ! $create_post_format && ! $raw ) { 113 $post_formats = $this->get_post_formats(); 114 $create_post_format = reset( $post_formats ); 115 } 116 return $create_post_format; 117 } 118 110 119 public function get_view_post_types() { 111 120 $view_post_types = get_term_meta( $this->term->term_id, 'view_post_types', true ); … … 143 152 public function set_create_post_type( $create_post_type ) { 144 153 return update_term_meta( $this->term->term_id, 'create_post_type', $create_post_type ); 154 } 155 156 public function set_create_post_format( $create_post_format ) { 157 return update_term_meta( $this->term->term_id, 'create_post_format', $create_post_format ); 145 158 } 146 159 … … 235 248 236 249 /** 250 * Get the text to display to the user about the current settings. 251 * 252 * @param string $content The content. 253 * 254 * @return string The current settings. 255 */ 256 public function get_current_settings_text( string $content = '' ) { 257 $post_formats = $this->get_post_formats(); 258 $post_format_strings = array_filter( 259 get_post_format_strings(), 260 function ( $slug ) use ( $post_formats ) { 261 return in_array( $slug, $post_formats, true ); 262 }, 263 ARRAY_FILTER_USE_KEY 264 ); 265 266 if ( empty( $post_format_strings ) ) { 267 // translators: %s is a list of post formats. 268 $content .= PHP_EOL . sprintf( _n( 'Post Format: %s', 'Post Formats: %s', count( get_post_format_strings() ), 'enable-mastodon-apps' ), __( 'All' ) ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain 269 } else { 270 // translators: %s is a list of post formats. 271 $content .= PHP_EOL . sprintf( _n( 'Post Format: %s', 'Post Formats: %s', count( $post_format_strings ), 'enable-mastodon-apps' ), implode( ', ', $post_format_strings ) ); 272 } 273 274 if ( empty( $post_format_strings ) ) { 275 $post_format_strings = get_post_format_strings(); 276 } 277 278 $content .= PHP_EOL . _x( 'Create new posts as', 'select post type', 'enable-mastodon-apps' ) . ': '; 279 $content .= get_post_type_object( $this->get_create_post_type() )->labels->singular_name; 280 $content .= ' ' . _x( 'in the post format', 'select post type', 'enable-mastodon-apps' ) . ': '; 281 if ( $this->get_create_post_format() && isset( $post_format_strings[ $this->get_create_post_format() ] ) ) { 282 $content .= $post_format_strings[ $this->get_create_post_format() ]; 283 } else { 284 $content .= reset( $post_format_strings ); 285 } 286 287 $t = PHP_EOL . __( 'Show these post types', 'enable-mastodon-apps' ) . ': '; 288 foreach ( $this->get_view_post_types() as $post_type ) { 289 if ( in_array( $post_type, array( Comment_CPT::CPT ), true ) ) { 290 continue; 291 } 292 $content .= $t . get_post_type_object( $post_type )->labels->name; 293 $t = ', '; 294 } 295 296 if ( $this->get_disable_blocks() ) { 297 $content .= PHP_EOL . __( 'Automatic conversion to blocks is disabled', 'enable-mastodon-apps' ); 298 } 299 300 return trim( $content ); 301 } 302 303 /** 237 304 * Posts current settings as an announcement just for this app. 238 305 * … … 258 325 $intro = __( 'The current settings for this app are:', 'enable-mastodon-apps' ); 259 326 } 260 $content = $intro; 261 262 $post_formats = $this->get_post_formats(); 263 $t = PHP_EOL . __( 'Post Formats', 'enable-mastodon-apps' ) . ': '; 264 foreach ( get_post_format_strings() as $slug => $name ) { 265 if ( ! in_array( $slug, $post_formats, true ) ) { 266 continue; 267 } 268 $content .= $t . $name; 269 $t = ', '; 270 } 271 if ( ', ' !== $t ) { 272 $content .= $t . __( 'All' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain 273 } 274 275 $content .= PHP_EOL . _x( 'Create new posts as', 'select post type', 'enable-mastodon-apps' ) . ': '; 276 $content .= get_post_type_object( $this->get_create_post_type() )->labels->singular_name; 277 $t = PHP_EOL . __( 'Show these post types', 'enable-mastodon-apps' ) . ': '; 278 foreach ( $this->get_view_post_types() as $post_type ) { 279 if ( in_array( $post_type, array( Mastodon_API::ANNOUNCE_CPT, Mastodon_API::POST_CPT ), true ) ) { 280 continue; 281 } 282 $content .= $t . get_post_type_object( $post_type )->labels->name; 283 $t = ', '; 284 } 285 286 if ( $this->get_disable_blocks() ) { 287 $content .= PHP_EOL . __( 'Automatic conversion to blocks is disabled', 'enable-mastodon-apps' ); 288 } 327 $content = $this->get_current_settings_text( $intro ); 289 328 290 329 $previous_posts = get_posts( … … 305 344 } 306 345 307 returnwp_insert_post(346 $post_id = wp_insert_post( 308 347 array( 309 348 'post_type' => Mastodon_API::ANNOUNCE_CPT, … … 316 355 ) 317 356 ); 357 if ( $post_id ) { 358 // Assign all post formats so that it will be shown regardless of the app's (potentially later changed) post format settings. 359 wp_set_object_terms( 360 $post_id, 361 array_map( 362 function ( $slug ) { 363 return 'post-format-' . $slug; 364 }, 365 get_post_format_slugs() 366 ), 367 'post_format' 368 ); 369 } 370 return $post_id; 318 371 } 319 372 … … 756 809 ); 757 810 811 $post_formats = array(); 812 if ( get_option( 'mastodon_api_default_create_post_format' ) ) { 813 $post_formats[] = get_option( 'mastodon_api_default_create_post_format' ); 814 } 758 815 /** 759 816 * Post formats to be enabled for new apps. … … 771 828 * ``` 772 829 */ 773 $post_formats = apply_filters( 'mastodon_api_new_app_post_formats', array(), $app_metadata ); 830 $post_formats = apply_filters( 'mastodon_api_new_app_post_formats', $post_formats, $app_metadata ); 831 774 832 $app_metadata['query_args'] = array( 'post_formats' => $post_formats ); 775 833 … … 778 836 if ( ! in_array( $app_metadata['create_post_type'], $view_post_types ) ) { 779 837 $view_post_types[] = $app_metadata['create_post_type']; 838 } 839 840 if ( get_option( 'mastodon_api_default_create_post_format' ) && in_array( get_option( 'mastodon_api_default_create_post_format' ), $post_formats ) ) { 841 $app_metadata['create_post_format'] = get_option( 'mastodon_api_default_create_post_format' ); 780 842 } 781 843 -
enable-mastodon-apps/trunk/includes/handler/class-status.php
r3245133 r3248503 131 131 $post = get_post( $object_id ); 132 132 133 if ( Mastodon_API::ANNOUNCE_CPT === $post->post_type ) {133 if ( $post && Mastodon_API::ANNOUNCE_CPT === $post->post_type ) { 134 134 $meta = get_post_meta( $post->ID, 'ema_app_id', true ); 135 135 $app = Mastodon_App::get_current_app(); -
enable-mastodon-apps/trunk/templates/app.php
r3245133 r3248503 30 30 ); 31 31 $app_post_formats = $app->get_post_formats(); 32 $selected_post_format = $app->get_create_post_format(); 33 if ( ! $selected_post_format ) { 34 $selected_post_format = 'standard'; 35 } 32 36 ?> 33 37 <div class="enable-mastodon-apps-settings enable-mastodon-apps-registered-apps-page <?php echo $args['enable_debug'] ? 'enable-debug' : 'disable-debug'; ?>"> … … 141 145 <?php endforeach; ?> 142 146 </select> 147 <label> 148 <?php echo esc_html( _x( 'in the post format', 'select post format', 'enable-mastodon-apps' ) ); ?> 149 <select name="create_post_format"> 150 <option value="" <?php selected( ! $app->get_create_post_format( true ) ); ?>><?php esc_html_e( 'First selected above', 'enable-mastodon-apps' ); ?> (<?php echo esc_html( get_post_format_strings()[ $selected_post_format ] ); ?>)</option> 151 152 <?php foreach ( get_post_format_strings() as $format => $label ) : ?> 153 <option value="<?php echo esc_attr( $format ); ?>" <?php selected( $format, $app->get_create_post_format( true ) ); ?><?php disabled( ! empty( $app_post_formats ) && ! in_array( $format, $app_post_formats, true ) ); ?>><?php echo esc_html( $label ); ?></option> 154 <?php endforeach; ?> 155 </select> 156 </label> 157 143 158 <p class="description"> 144 159 <span><?php esc_html_e( 'When posting through the app, this post type will be created.', 'enable-mastodon-apps' ); ?></span> … … 218 233 ); 219 234 ?> 220 </button> 221 <script> 222 document.getElementById( 'toggle_all_post_formats' ).onclick = function ( event ) { 223 document.querySelectorAll( '.post-formats input[type="checkbox"]' ).forEach( function ( element ) { 224 element.checked = ! element.checked; 225 } ); 226 227 event.preventDefault(); 228 return false; 229 } 230 </script> 235 </button> 231 236 232 237 <h3><?php esc_html_e( 'Access Tokens', 'enable-mastodon-apps' ); ?></h3> … … 283 288 </form> 284 289 </div> 290 <script type="text/javascript"> 291 document.addEventListener( 'click', function ( event ) { 292 function updatePostFormatDropdown( el ) { 293 const postFormats = document.querySelectorAll( '.post-formats input[type="checkbox"]:checked' ); 294 const postFormatSelect = document.querySelector( 'select[name="create_post_format"]' ); 295 const options = postFormatSelect.querySelectorAll( 'option' ); 296 297 for ( const option of options ) { 298 if ( option.value === el.value ) { 299 option.disabled = ! el.checked; 300 if ( ! el.checked && postFormatSelect.value === el.value ) { 301 postFormatSelect.value = ''; 302 } 303 } 304 } 305 const selectedPostFormat = postFormats.length ? postFormats[0] : document.querySelector( '.post-formats input[type="checkbox"]' ); 306 options[0].textContent = options[0].textContent.replace( /\(.*\)/, '(' + selectedPostFormat.nextSibling.textContent.trim() + ')' ); 307 } 308 309 if ( event.target.matches( '.post-formats input[type="checkbox"]' ) ) { 310 return updatePostFormatDropdown( event.target ); 311 } 312 if ( event.target.id === 'toggle_all_post_formats' ) { 313 event.preventDefault(); 314 document.querySelectorAll( '.post-formats input[type="checkbox"]' ).forEach( function ( element ) { 315 element.checked = ! element.checked; 316 updatePostFormatDropdown( element ); 317 } ); 318 return; 319 } 320 }); 321 </script> -
enable-mastodon-apps/trunk/templates/registered-apps.php
r3157710 r3248503 43 43 <th><?php esc_html_e( 'Name', 'enable-mastodon-apps' ); ?></th> 44 44 <th class="debug-hide"><?php esc_html_e( 'Redirect URI', 'enable-mastodon-apps' ); ?></th> 45 <th><?php esc_html_e( 'Scope', 'enable-mastodon-apps' ); ?></th> 46 <th class="debug-hide"><?php esc_html_e( 'Post Formats', 'enable-mastodon-apps' ); ?></th> 45 <th><?php echo esc_html_x( 'Create new posts as', 'select post type', 'enable-mastodon-apps' ); ?></th> 46 <th><?php echo esc_html_x( 'in the post format', 'select post format', 'enable-mastodon-apps' ); ?></th> 47 <th><?php esc_html_e( 'Post Formats', 'enable-mastodon-apps' ); ?></th> 48 <th class="debug-hide"><?php esc_html_e( 'Scope', 'enable-mastodon-apps' ); ?></th> 47 49 <th><?php esc_html_e( 'Last Used', 'enable-mastodon-apps' ); ?></th> 48 50 <th><?php esc_html_e( 'Created', 'enable-mastodon-apps' ); ?></th> … … 69 71 </td> 70 72 <td class="debug-hide"><?php echo wp_kses( implode( '<br/>', is_array( $app->get_redirect_uris() ) ? $app->get_redirect_uris() : explode( ',', $app->get_redirect_uris() ) ), array( 'br' => array() ) ); ?></td> 71 <td><?php echo esc_html( $app->get_scopes() ); ?></td> 72 <td class="debug-hide"> 73 <td> 73 74 <?php 74 foreach ( get_post_format_strings() as $format => $label ) { 75 if ( in_array( $format, $app->get_post_formats() ) ) { 76 echo esc_html( $label ) . '<br>'; 75 $_post_type = get_post_type_object( $app->get_create_post_type() ); 76 echo esc_html( $_post_type->labels->singular_name ); 77 ?> 78 </td> 79 <td> 80 <?php 81 if ( ! $app->get_create_post_format() ) { 82 echo esc_html_x( 'Standard', 'Post format' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain 83 84 } else { 85 foreach ( get_post_format_strings() as $slug => $name ) { 86 if ( $slug === $app->get_create_post_format() ) { 87 echo esc_html( $name ); 88 break; 89 } 77 90 } 78 91 } 79 92 ?> 80 93 </td> 94 <td> 95 <?php 96 97 $post_formats = $app->get_post_formats(); 98 if ( empty( $post_formats ) ) { 99 echo esc_html( __( 'All' ) ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain 100 } else { 101 echo esc_html( 102 implode( 103 ', ', 104 array_map( 105 function ( $slug ) { 106 return get_post_format_strings()[ $slug ]; 107 }, 108 $post_formats 109 ) 110 ) 111 ); 112 } 113 ?> 114 </td> 115 <td class="debug-hide"><?php echo esc_html( $app->get_scopes() ); ?></td> 81 116 <?php td_timestamp( $app->get_last_used() ); ?> 82 117 <?php td_timestamp( $app->get_creation_date() ); ?> -
enable-mastodon-apps/trunk/templates/settings.php
r3245133 r3248503 30 30 </tr> 31 31 <tr> 32 <th scope="row" ><?php esc_html_e( 'Posting', 'enable-mastodon-apps' ); ?></th>32 <th scope="row" rowspan="2"><?php esc_html_e( 'Posting', 'enable-mastodon-apps' ); ?></th> 33 33 <td> 34 34 <fieldset> 35 <label for="mastodon_api_no_posting_cpt"> 36 <input name="mastodon_api_posting_cpt" type="radio" id="mastodon_api_no_posting_cpt" value="1" <?php checked( ! get_option( 'mastodon_api_posting_cpt' ) ); ?> /> 37 <span><?php esc_html_e( 'Hide posts through Mastodon apps from appearing on the WordPress frontend', 'enable-mastodon-apps' ); ?></span> 38 </label> 35 39 <label for="mastodon_api_posting_cpt"> 36 <input name="mastodon_api_posting_cpt" type=" checkbox" id="mastodon_api_posting_cpt" value="1" <?php checked( !get_option( 'mastodon_api_posting_cpt' ) ); ?> />37 <span><?php esc_html_e( ' Hide posts through Mastodon apps from appearingon the WordPress frontend', 'enable-mastodon-apps' ); ?></span>40 <input name="mastodon_api_posting_cpt" type="radio" id="mastodon_api_posting_cpt" value="0" <?php checked( 'post' === get_option( 'mastodon_api_posting_cpt' ) ); ?> /> 41 <span><?php esc_html_e( 'Show posts through Mastodon apps on the WordPress frontend', 'enable-mastodon-apps' ); ?></span> 38 42 </label> 39 43 </fieldset> … … 71 75 </span> 72 76 </p> 77 </td> 78 </tr> 79 <tr> 80 <td> 81 <fieldset> 82 <label for="mastodon_api_default_create_post_format"> 83 <?php esc_html_e( 'For new apps, pre-select this post format:', 'enable-mastodon-apps' ); ?> 84 </label> 85 <select name="mastodon_api_default_create_post_format" id="mastodon_api_default_create_post_format"> 86 <option value="all" <?php selected( ! get_option( 'mastodon_api_default_create_post_format' ) ); ?>><?php esc_html_e( 'None', 'enable-mastodon-apps' ); ?></option> 87 <?php foreach ( get_post_format_strings() as $format => $label ) : ?> 88 <option value="<?php echo esc_attr( $format ); ?>" <?php selected( $format, get_option( 'mastodon_api_default_create_post_format' ) ); ?>><?php echo esc_html( $label ); ?></option> 89 <?php endforeach; ?> 90 </select> 91 <p class="description"> 92 <?php esc_html_e( 'If no post format is selected, posts in all post formats will be displayed.', 'enable-mastodon-apps' ); ?> 93 </p> 94 </fieldset> 73 95 </td> 74 96 </tr>
Note: See TracChangeset
for help on using the changeset viewer.