Changeset 3240587
- Timestamp:
- 02/14/2025 11:46:47 AM (3 weeks ago)
- Location:
- enable-mastodon-apps/trunk
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
enable-mastodon-apps/trunk/README.md
r3165316 r3240587 7 7 - Requires PHP: 7.4 8 8 - License: [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) 9 - Stable tag: 0.9.99 - Stable tag: 1.0.0 10 10 11 11 Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance. … … 99 99 ## Changelog 100 100 101 ### 1.0.0 102 - Post through Mastodon Apps to a new post type by default ([#192]) 103 - Explain the new hide posts setting better ([#198]) 104 - Don't enforce parameters on non-EMA REST requests ([#197]) 105 - Add missing CPT supports ([#196]) 106 - Don't show reblog mapping posts ([#193]) 107 - Update PHPCompatibility and restrict PHPUnit ([#195]) 108 - Add missing svn in Github Actions ([#194]) 109 - Improve REST Authentication Error Debugging ([#191]) 110 - Use title instead of post_content when there is no line break ([#185]) 111 - Fix wp:image block created for attachments ([#184]) 112 101 113 ### 0.9.9 102 114 - Improve targeting of CORS headers ([#181]) -
enable-mastodon-apps/trunk/composer.json
r3157710 r3240587 1 1 { 2 "name": "akirk/enable-mastodon-apps", 3 "description": "A WordPress plugin that implements the Mastodon API to enable access through Mastodon apps", 4 "type": "wordpress-plugin", 5 "license": "GPL-2.0-or-later", 6 "require-dev": { 7 "dealerdirect/phpcodesniffer-composer-installer": "*", 8 "phpcompatibility/php-compatibility": "*", 9 "wp-coding-standards/wpcs": "*", 10 "yoast/phpunit-polyfills": "*", 11 "php-parallel-lint/php-parallel-lint": "^1.3", 12 "phpunit/phpunit": "*", 13 "akirk/extract-wp-hooks": "*" 14 }, 15 "config": { 16 "allow-plugins": { 17 "dealerdirect/phpcodesniffer-composer-installer": true 18 } 19 }, 20 "prefer-stable": true, 21 "scripts": { 22 "lint7": [ 23 "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --exclude src/Exceptions/Error.php --exclude src/Exceptions/TypeError.php --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionNoReturnType.php" 24 ], 25 "lint-lt70": [ 26 "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --exclude src/TestCases/TestCasePHPUnitGte8.php --exclude src/TestListeners/TestListenerDefaultImplementationPHPUnitGte7.php --exclude tests/Polyfills/Fixtures/ChildValueObject.php --exclude tests/Polyfills/Fixtures/ValueObject.php --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionNoReturnType.php" 27 ], 28 "lint-gte80": [ 29 "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" 30 ], 31 "check-cs": [ 32 "@php ./vendor/bin/phpcs" 33 ], 34 "fix-cs": [ 35 "@php ./vendor/bin/phpcbf" 36 ], 37 "test": [ 38 "@php ./vendor/phpunit/phpunit/phpunit --no-coverage" 39 ], 40 "docker-test": [ 41 "composer install", 42 "bin/install-wp-tests.sh ema-test root ema-test test-db latest true", 43 "@php ./vendor/phpunit/phpunit/phpunit --no-coverage" 44 ], 45 "update-wiki": [ 46 "test -d ../enable-mastodon-apps.wiki && php ./vendor/akirk/extract-wp-hooks/extract-wp-hooks.php && cd ../enable-mastodon-apps.wiki/ && git add . && git commit -m 'Update hooks'; git push" 47 ] 48 }, 49 "require": { 50 "bshaffer/oauth2-server-php": "^1.10" 51 } 2 "name": "akirk/enable-mastodon-apps", 3 "description": "A WordPress plugin that implements the Mastodon API to enable access through Mastodon apps", 4 "license": "GPL-2.0-or-later", 5 "require-dev": { 6 "phpcompatibility/php-compatibility": "dev-develop as 9.99.99", 7 "phpcompatibility/phpcompatibility-wp": "*", 8 "wp-coding-standards/wpcs": "*", 9 "yoast/phpunit-polyfills": "*", 10 "php-parallel-lint/php-parallel-lint": "^1.3", 11 "phpunit/phpunit": "9.*", 12 "akirk/extract-wp-hooks": "*" 13 }, 14 "config": { 15 "allow-plugins": { 16 "dealerdirect/phpcodesniffer-composer-installer": true 17 } 18 }, 19 "prefer-stable": true, 20 "scripts": { 21 "lint7": [ 22 "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --exclude src/Exceptions/Error.php --exclude src/Exceptions/TypeError.php --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionNoReturnType.php" 23 ], 24 "lint-lt70": [ 25 "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --exclude src/TestCases/TestCasePHPUnitGte8.php --exclude src/TestListeners/TestListenerDefaultImplementationPHPUnitGte7.php --exclude tests/Polyfills/Fixtures/ChildValueObject.php --exclude tests/Polyfills/Fixtures/ValueObject.php --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionNoReturnType.php" 26 ], 27 "lint-gte80": [ 28 "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" 29 ], 30 "check-cs": [ 31 "@php ./vendor/bin/phpcs" 32 ], 33 "fix-cs": [ 34 "@php ./vendor/bin/phpcbf" 35 ], 36 "test": [ 37 "@php ./vendor/phpunit/phpunit/phpunit --no-coverage" 38 ], 39 "docker-test": [ 40 "composer install", 41 "bin/install-wp-tests.sh ema-test root ema-test test-db latest true", 42 "@php ./vendor/phpunit/phpunit/phpunit --no-coverage" 43 ], 44 "update-wiki": [ 45 "test -d ../enable-mastodon-apps.wiki && php ./vendor/akirk/extract-wp-hooks/extract-wp-hooks.php && cd ../enable-mastodon-apps.wiki/ && git add . && git commit -m 'Update hooks'; git push" 46 ] 47 }, 48 "require": { 49 "bshaffer/oauth2-server-php": "^1.10" 50 } 52 51 } -
enable-mastodon-apps/trunk/enable-mastodon-apps.php
r3165316 r3240587 4 4 * Plugin author: Alex Kirk 5 5 * Plugin URI: https://github.com/akirk/enable-mastodon-apps 6 * Version: 0.9.96 * Version: 1.0.0 7 7 * 8 8 * Description: Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance. … … 20 20 defined( 'ABSPATH' ) || exit; 21 21 define( 'ENABLE_MASTODON_APPS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 22 define( 'ENABLE_MASTODON_APPS_VERSION', ' 0.9.9' );22 define( 'ENABLE_MASTODON_APPS_VERSION', '1.0.0' ); 23 23 24 24 require __DIR__ . '/vendor/bshaffer/oauth2-server-php/src/OAuth2/Autoloader.php'; -
enable-mastodon-apps/trunk/includes/class-mastodon-admin.php
r3129164 r3240587 19 19 add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 20 20 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); 21 add_action( 'current_screen', array( $this, 'register_help' ) ); 21 22 } 22 23 … … 43 44 } 44 45 46 public function register_help( $screen ) { 47 if ( 'settings_page_enable-mastodon-apps' !== $screen->id ) { 48 return; 49 } 50 $ema_post_cpt = get_post_type_object( apply_filters( 'mastodon_api_default_post_type', \Enable_Mastodon_Apps\Mastodon_API::POST_CPT ) ); 51 $post_cpt = get_post_type_object( 'post' ); 52 53 $screen->add_help_tab( 54 array( 55 'id' => 'enable-mastodon-apps-help', 56 'title' => __( 'Settings' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain 57 'content' => 58 '<p><strong>' . esc_html__( 'Make posts through Mastodon apps appear on this WordPress', 'enable-mastodon-apps' ) . '</strong><br>' . 59 '<span>' . esc_html__( 'Setting this depends on your use case:', 'enable-mastodon-apps' ) . '</span>' . 60 '<ul>' . 61 '<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, check the box.', 'enable-mastodon-apps' ) . '</li>' . 62 '<li>' . 63 wp_kses( 64 sprintf( 65 // translators: Links to the plugins. 66 __( '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 unchecked.', 'enable-mastodon-apps' ), 67 'https://wordpress.org/plugins/friends/" target="_blank', 68 'https://wordpress.org/plugins/activitypub/" target="_blank' 69 ), 70 array( 71 'a' => array( 72 'href' => true, 73 'target' => true, 74 ), 75 ) 76 ) . 77 '</li>' . 78 '<li>' . 79 wp_kses( 80 sprintf( 81 // translators: Links to the plugins. 82 __( 'If you do want to expose such posts also on your site (for example in a <a href="%s">POSSE</a> use case), check the box.', 'enable-mastodon-apps' ), 83 'https://indieweb.org/POSSE" target="_blank' 84 ), 85 array( 86 'a' => array( 87 'href' => true, 88 'target' => true, 89 ), 90 ) 91 ) . 92 '</li>' . 93 '</ul>' . 94 '<span>' . 95 wp_kses( 96 sprintf( 97 // translators: %1$s and %2$s: a post type. 98 __( 'When checked, new posts made through Mastodon apps will have the post type %1$s, otherwise %2$s when unchecked.', 'enable-mastodon-apps' ), 99 '<strong>' . $ema_post_cpt->labels->singular_name . '</strong>', 100 '<strong>' . $post_cpt->labels->singular_name . '</strong>' 101 ), 102 array( 'strong' => true ) 103 ) . 104 '</span>' . 105 '</p>', 106 ) 107 ); 108 } 109 110 111 45 112 public function process_admin() { 46 113 if ( ! current_user_can( 'edit_private_posts' ) ) { … … 67 134 case 'settings': 68 135 $this->process_admin_settings_page(); 136 // We need to reload the page so that the POST_CPT shows up in the correct state. 137 wp_safe_redirect( admin_url( 'options-general.php?page=enable-mastodon-apps&tab=settings' ) ); 69 138 break; 70 139 case 'debug': … … 126 195 } 127 196 197 /** 198 * The default post type for posting from Mastodon apps when the configured to do so. 199 * 200 * This only applies if the user unchekcks: Make posts through Mastodon apps appear on this WordPress 201 * 202 * @param string $post_type The default post type. 203 * 204 * Example: 205 * ```php 206 * add_filter( 'mastodon_api_default_post_type', function( $post_type ) { 207 * return 'my-own-custom-post-type'; 208 * } ); 209 * ``` 210 */ 211 $default_ema_post_type = apply_filters( 'mastodon_api_default_post_type', \Enable_Mastodon_Apps\Mastodon_API::POST_CPT ); 212 213 if ( isset( $_POST['mastodon_api_posting_cpt'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing 214 delete_option( 'mastodon_api_posting_cpt' ); 215 216 $supported_post_types = (array) \get_option( 'activitypub_support_post_types', array( 'post' ) ); 217 $supported_post_types[] = $default_ema_post_type; 218 \update_option( 'activitypub_support_post_types', $supported_post_types ); 219 } else { 220 update_option( 'mastodon_api_posting_cpt', 'post' ); 221 222 $supported_post_types = (array) \get_option( 'activitypub_support_post_types', array( 'post' ) ); 223 if ( in_array( $default_ema_post_type, $supported_post_types, true ) ) { 224 $supported_post_types = array_diff( $supported_post_types, array( $default_ema_post_type ) ); 225 \update_option( 'activitypub_support_post_types', $supported_post_types ); 226 } 227 } 228 128 229 if ( isset( $_POST['mastodon_api_enable_debug'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing 129 230 update_option( 'mastodon_api_enable_debug', true ); … … 611 712 } 612 713 714 if ( version_compare( $old_version, '1.0.0', '<' ) ) { 715 // If the friends plugin is installed, add the friends post type to the list of post types that can be viewed. 716 if ( class_exists( 'Friends\Friends' ) ) { 717 $apps = Mastodon_App::get_all(); 718 foreach ( $apps as $app ) { 719 $view_post_types = $app->get_view_post_types(); 720 $view_post_types[] = \Friends\Friends::CPT; 721 $app->set_view_post_types( $view_post_types ); 722 } 723 } 724 } 725 613 726 if ( version_compare( $old_version, '0.9.1', '<' ) ) { 614 727 $comment_posts = get_posts( -
enable-mastodon-apps/trunk/includes/class-mastodon-api.php
r3165316 r3240587 34 34 private $oauth; 35 35 36 /**37 * The Mastodon App.38 *39 * @var Mastodon_App40 */41 private $app;42 43 36 private static $last_error = false; 44 37 … … 47 40 const REMAP_TAXONOMY = 'mastodon-api-remap'; 48 41 const CPT = 'enable-mastodon-apps'; 42 const POST_CPT = 'ema-post'; 49 43 50 44 /** … … 56 50 $this->register_hooks(); 57 51 $this->register_taxonomy(); 58 $this->register_custom_post_type ();52 $this->register_custom_post_types(); 59 53 new Mastodon_Admin( $this->oauth ); 60 54 … … 80 74 add_filter( 'rest_json_encode_options', array( $this, 'rest_json_encode_options' ), 10, 2 ); 81 75 add_action( 'default_option_mastodon_api_default_post_formats', array( $this, 'default_option_mastodon_api_default_post_formats' ) ); 82 add_filter( 'rest_request_before_callbacks', array( $this, 'rest_request_before_callbacks' ) ); 76 add_filter( 'rest_request_before_callbacks', array( $this, 'rest_request_before_callbacks' ), 10, 3 ); 77 add_filter( 'rest_authentication_errors', array( $this, 'rest_authentication_errors' ) ); 83 78 add_filter( 'mastodon_api_mapback_user_id', array( $this, 'mapback_user_id' ) ); 84 79 add_filter( 'mastodon_api_in_reply_to_id', array( self::class, 'maybe_get_remapped_reblog_id' ), 15 ); 80 add_filter( 'activitypub_support_post_types', array( $this, 'activitypub_support_post_types' ) ); 85 81 } 86 82 … … 174 170 } 175 171 176 public function register_custom_post_type () {172 public function register_custom_post_types() { 177 173 $args = array( 178 174 'labels' => array( … … 189 185 190 186 register_post_type( self::CPT, $args ); 191 } 192 193 187 188 $args = array( 189 'labels' => array( 190 'name' => __( 'Mastodon Posts', 'enable-mastodon-apps' ), 191 'singular_name' => __( 'Mastodon Post', 'enable-mastodon-apps' ), 192 'menu_name' => __( 'Mastodon Posts', 'enable-mastodon-apps' ), 193 ), 194 'description' => __( 'Posted through a Mastodon app.', 'enable-mastodon-apps' ), 195 'public' => ! get_option( 'mastodon_api_posting_cpt' ), 196 'show_in_rest' => false, 197 'rewrite' => false, 198 'menu_icon' => 'dashicons-megaphone', 199 'supports' => array( 'post-formats', 'comments', 'revisions', 'author' ), 200 ); 201 202 register_post_type( self::POST_CPT, $args ); 203 } 204 205 public function activitypub_support_post_types( $post_types ) { 206 $post_types[] = self::POST_CPT; 207 return $post_types; 208 } 194 209 public function rewrite_rules() { 195 210 $existing_rules = get_option( 'rewrite_rules' ); … … 1813 1828 * 1814 1829 * @param WP_REST_Response|\WP_HTTP_Response|\WP_Error|mixed $response Result to send to the client. 1830 * @param WP_REST_Server $handler The handler instance. 1831 * @param WP_REST_Request $request Thr request. 1832 * 1815 1833 * @return WP_REST_Response|\WP_HTTP_Response|\WP_Error|mixed 1816 1834 */ 1817 public function rest_request_before_callbacks( $response ) { 1835 public function rest_request_before_callbacks( $response, $handler, $request ) { 1836 if ( 0 !== strpos( $request->get_route(), '/' . self::PREFIX ) ) { 1837 return $response; 1838 } 1839 1818 1840 if ( is_wp_error( $response ) && 'rest_missing_callback_param' === $response->get_error_code() ) { 1819 1841 $response = new \WP_Error( $response->get_error_code(), $response->get_error_message(), array( 'status' => 422 ) ); … … 1821 1843 1822 1844 return $response; 1845 } 1846 1847 /** 1848 * Log REST API errors for debugging. 1849 * 1850 * @param WP_Error $errors WP_Error object. 1851 * @return WP_Error WP_Error object. 1852 */ 1853 public function rest_authentication_errors( $errors ) { 1854 if ( $errors && get_option( 'mastodon_api_debug_mode' ) > time() ) { 1855 $request = new WP_REST_Request( $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'] ); // phpcs:ignore 1856 $request->set_query_params( $_GET ); // phpcs:ignore 1857 $request->set_body_params( $_POST ); // phpcs:ignore 1858 $request->set_headers( getallheaders() ); 1859 1860 $app = Mastodon_App::get_debug_app(); 1861 $app->was_used( 1862 $request, 1863 array( 1864 'user_agent' => $_SERVER['HTTP_USER_AGENT'], // phpcs:ignore 1865 'errors' => $errors, 1866 ) 1867 ); 1868 } 1869 1870 return $errors; 1823 1871 } 1824 1872 … … 2111 2159 * Example: 2112 2160 * ```php 2161 * add_filter( 'mastodon_api_public_timeline', function( $statuses, $request ) { 2162 * array_unshift( $statuses, new Entity\Status( array( 'content' => 'Hello World' ) ) ); 2163 * return $statuses; 2164 * } ); 2113 2165 * ``` 2114 2166 */ -
enable-mastodon-apps/trunk/includes/class-mastodon-app.php
r3158300 r3240587 101 101 $create_post_type = 'post'; 102 102 } 103 return apply_filters( 'mastodon_api_create_post_type', $create_post_type );103 return $create_post_type; 104 104 } 105 105 … … 112 112 $view_post_types = array( $view_post_types ); 113 113 } 114 return apply_filters( 'mastodon_api_view_post_types', $view_post_types );114 return $view_post_types; 115 115 } 116 116 … … 519 519 continue; 520 520 } 521 if ( ( 'files' === $key || 'params' === $key || 'json' === $key ) && ! empty( $value[ $key ] ) ) { 521 if ( 522 ( 523 'files' === $key || 524 'params' === $key || 525 'json' === $key || 526 'errors' === $key 527 ) && 528 ! empty( $value[ $key ] ) 529 ) { 522 530 continue; 523 531 } … … 651 659 652 660 $post_formats = get_option( 'mastodon_api_default_post_formats', array() ); 661 /** 662 * Post formats to be enabled for new apps. 663 * 664 * @param array $post_formats The post formats. 665 * 666 * @return array The post formats. 667 * 668 * Example: 669 * ```php 670 * add_filter( 'mastodon_api_new_app_post_formats', function( $post_formats ) { 671 * // This will enable standard and aside post formats for new apps. 672 * return array( 'standard', 'aside' ); 673 * } ); 674 * ``` 675 */ 653 676 $post_formats = apply_filters( 'mastodon_api_new_app_post_formats', $post_formats, $app_metadata ); 677 $app_metadata['query_args'] = array( 'post_formats' => $post_formats ); 678 679 $app_metadata['create_post_type'] = get_option( 'mastodon_api_posting_cpt', apply_filters( 'mastodon_api_default_post_type', \Enable_Mastodon_Apps\Mastodon_API::POST_CPT ) ); 680 $view_post_types = array( 'post', 'comment' ); 681 if ( ! in_array( $app_metadata['create_post_type'], $view_post_types ) ) { 682 $view_post_types[] = $app_metadata['create_post_type']; 683 } 684 685 /** 686 * Standard post types that the app can view. 687 * 688 * @param array $view_post_types The post types. 689 * 690 * @return array The post types. 691 * 692 * Example: 693 * ```php 694 * add_filter( 'mastodon_api_view_post_types', function( $view_post_types ) { 695 * // This will allow the app to view pages. 696 * return array_merge( $view_post_types, array( 'page' ) ); 697 * } ); 698 * ``` 699 */ 700 $app_metadata['view_post_types'] = apply_filters( 'mastodon_api_view_post_types', $view_post_types ); 654 701 655 702 $term_id = $term['term_id']; -
enable-mastodon-apps/trunk/includes/handler/class-handler.php
r3129164 r3240587 10 10 namespace Enable_Mastodon_Apps\Handler; 11 11 12 use Enable_Mastodon_Apps\Mastodon_API;13 12 use Enable_Mastodon_Apps\Mastodon_App; 14 13 … … 26 25 27 26 if ( ! isset( $args['post_type'] ) ) { 28 $post_types = array( 'post' );27 $post_types = array( 'post', 'comment' ); 29 28 if ( $app ) { 30 29 $post_types = $app->get_view_post_types(); 31 30 } 32 $args['post_type'] = array_merge( $post_types, array( Mastodon_API::CPT ) );31 $args['post_type'] = $post_types; 33 32 } 34 33 $args['posts_per_page'] = $limit; -
enable-mastodon-apps/trunk/includes/handler/class-status.php
r3158797 r3240587 254 254 $post_content = array_map( 'trim', $post_content ); 255 255 $post_content = array_filter( $post_content ); 256 if ( empty( $post_content ) ) { 257 return ''; 258 } 256 259 $post_content = '<!-- wp:paragraph -->' . PHP_EOL . '<p>' . implode( '</p>' . PHP_EOL . '<!-- /wp:paragraph -->' . PHP_EOL . PHP_EOL . '<!-- wp:paragraph -->' . PHP_EOL . '<p>', $post_content ) . '</p>' . PHP_EOL . '<!-- /wp:paragraph -->'; 257 260 return $post_content; … … 272 275 273 276 if ( 'standard' === $post_format ) { 274 $post_content_parts = explode( PHP_EOL, $post_data['post_content'], 2 ); 275 if ( count( $post_content_parts ) === 2 ) { 276 $post_data['post_title'] = wp_strip_all_tags( $post_content_parts[0] ); 277 $post_data['post_content'] = trim( $post_content_parts[1] ); 278 } 277 $post_content_parts = explode( PHP_EOL, $post_data['post_content'] . PHP_EOL, 2 ); 278 $post_data['post_title'] = wp_strip_all_tags( $post_content_parts[0] ); 279 $post_data['post_content'] = trim( $post_content_parts[1] ); 279 280 } 280 281 … … 305 306 $post_data['post_content'] .= PHP_EOL; 306 307 $meta_json = array( 307 'id' => $media_id,308 'id' => intval( $media_id ), 308 309 'sizeSlug' => 'large', 309 310 ); 310 311 $post_data['post_content'] .= '<!-- wp:image ' . wp_json_encode( $meta_json ) . ' -->' . PHP_EOL; 311 $post_data['post_content'] .= '<figure class="wp-block-image"><img src="' . esc_url( wp_get_attachment_url( $media_id ) ) . '" width="' . esc_attr( $attachment['width'] ) . '" height="' . esc_attr( $attachment['height'] ) . '"alt="" class="wp-image-' . esc_attr( $media_id ) . '"/></figure>' . PHP_EOL;312 $post_data['post_content'] .= '<figure class="wp-block-image"><img src="' . esc_url( wp_get_attachment_url( $media_id ) ) . '" alt="" class="wp-image-' . esc_attr( $media_id ) . '"/></figure>' . PHP_EOL; 312 313 $post_data['post_content'] .= '<!-- /wp:image -->' . PHP_EOL; 313 314 } elseif ( \wp_attachment_is( 'video', $media_id ) ) { -
enable-mastodon-apps/trunk/includes/oauth2/class-mastodon-app-storage.php
r3129164 r3240587 106 106 $post_formats = get_option( 'mastodon_api_default_post_formats', array() ); 107 107 $post_formats = apply_filters( 'mastodon_api_new_app_post_formats', $post_formats, $app_metadata ); 108 $app_metadata['query_args'] = array( 'post_formats' => $post_formats ); 109 110 $app_metadata['create_post_type'] = get_option( 'mastodon_api_posting_cpt', apply_filters( 'mastodon_api_default_post_type', \Enable_Mastodon_Apps\Mastodon_API::POST_CPT ) ); 111 $view_post_types = array( 'post', 'comment' ); 112 if ( ! in_array( $app_metadata['create_post_type'], $view_post_types ) ) { 113 $view_post_types[] = $app_metadata['create_post_type']; 114 } 115 116 $app_metadata['view_post_types'] = apply_filters( 'mastodon_api_view_post_types', $view_post_types ); 108 117 109 118 $term_id = $term['term_id']; -
enable-mastodon-apps/trunk/templates/app.php
r3158300 r3240587 14 14 $rest_nonce = wp_create_nonce( 'wp_rest' ); 15 15 $_post_types = \get_post_types( array( 'show_ui' => true ), 'objects' ); 16 if ( ! isset( $_post_types[ \Enable_Mastodon_Apps\Mastodon_Api::POST_CPT ] ) ) { 17 $_post_types = array_merge( 18 array( 19 \Enable_Mastodon_Apps\Mastodon_Api::POST_CPT => get_post_type_object( \Enable_Mastodon_Apps\Mastodon_Api::POST_CPT ), 20 ), 21 $_post_types 22 ); 23 } 24 16 25 $app = $args['app']; 17 26 $confirm = esc_html( … … 131 140 <p class="description"> 132 141 <span><?php esc_html_e( 'When posting through the app, this post type will be created.', 'enable-mastodon-apps' ); ?></span> 142 <br> 143 <span> 144 <?php 145 echo wp_kses( 146 sprintf( 147 // translators: %s is a post type singular name that appears in the dropdown above. 148 __( 'Choose %s to make posts through Mastodon apps appear on this WordPress.', 'enable-mastodon-apps' ), 149 '<strong>' . get_post_type_object( 'post' )->labels->singular_name . '</strong>' 150 ), 151 array( 'strong' => true ) 152 ); 153 154 ?> 155 </span> 156 <br> 157 <span> 158 <?php 159 echo wp_kses( 160 sprintf( 161 // translators: %s is a post type singular name that appears in the dropdown above. 162 __( 'Choose %s if you want to <strong>hide posts through Mastodon apps</strong> from this WordPress.', 'enable-mastodon-apps' ), 163 '<strong>' . __( 'Mastodon Post', 'enable-mastodon-apps' ) . '</strong>' 164 ), 165 array( 'strong' => true ) 166 ); 167 168 ?> 169 </span> 133 170 </p> 134 171 </td> -
enable-mastodon-apps/trunk/templates/settings.php
r3129164 r3240587 9 9 ) 10 10 ); 11 11 12 ?> 12 13 … … 29 30 </tr> 30 31 <tr> 32 <th scope="row"><?php esc_html_e( 'Posting', 'enable-mastodon-apps' ); ?></th> 33 <td> 34 <fieldset> 35 <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 appearing on the WordPress frontend', 'enable-mastodon-apps' ); ?></span> 38 </label> 39 </fieldset> 40 <p class="description"> 41 <span> 42 <?php 43 echo wp_kses( 44 sprintf( 45 // translators: %s: Help tab link. 46 __( 'To understand this setting better, please check <a href="" onclick="%s">Help tab</a> for some use cases.', 'enable-mastodon-apps' ), 47 'document.getElementById(\'contextual-help-link\').click(); return false;' 48 ), 49 array( 50 'a' => array( 51 'href' => true, 52 'onclick' => true, 53 ), 54 ) 55 ); 56 ?> 57 </span> 58 <br> 59 <span> 60 <?php 61 echo wp_kses( 62 sprintf( 63 // translators: %1$s: URL to the Mastodon API settings page Registered Apps tab, %2$s: Registered Apps tab title. 64 __( 'This setting only applies to newly registered apps, but you can change it individually for each app on the <a href="%1$s">%2$s</a> page.', 'enable-mastodon-apps' ), 65 esc_url( admin_url( 'admin.php?page=enable-mastodon-apps-settings&tab=registered-apps' ) ), 66 __( 'Registered Apps', 'enable-mastodon-apps' ) 67 ), 68 array( 'a' => array( 'href' => array() ) ) 69 ); 70 ?> 71 </span> 72 </p> 73 </td> 74 </tr> 75 <tr> 31 76 <th scope="row"><?php esc_html_e( 'Debugging', 'enable-mastodon-apps' ); ?></th> 32 77 <td> -
enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/ClientAssertionType/HttpBasic.php
r2888191 r3240587 113 113 * @ingroup oauth2_section_2 114 114 */ 115 public function getClientCredentials(RequestInterface $request, ResponseInterface $response = null)115 public function getClientCredentials(RequestInterface $request, ?ResponseInterface $response = null) 116 116 { 117 117 if (!is_null($request->headers('PHP_AUTH_USER')) && !is_null($request->headers('PHP_AUTH_PW'))) { -
enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Controller/AuthorizeController.php
r2985283 r3240587 79 79 * @endcode 80 80 */ 81 public function __construct(ClientInterface $clientStorage, array $responseTypes = array(), array $config = array(), ScopeInterface $scopeUtil = null)81 public function __construct(ClientInterface $clientStorage, array $responseTypes = array(), array $config = array(), ?ScopeInterface $scopeUtil = null) 82 82 { 83 83 $this->clientStorage = $clientStorage; -
enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Controller/ResourceController.php
r2888191 r3240587 48 48 * @param ScopeInterface $scopeUtil 49 49 */ 50 public function __construct(TokenTypeInterface $tokenType, AccessTokenInterface $tokenStorage, $config = array(), ScopeInterface $scopeUtil = null)50 public function __construct(TokenTypeInterface $tokenType, AccessTokenInterface $tokenStorage, $config = array(), ?ScopeInterface $scopeUtil = null) 51 51 { 52 52 $this->tokenType = $tokenType; -
enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Controller/TokenController.php
r2985283 r3240587 55 55 * @throws InvalidArgumentException 56 56 */ 57 public function __construct(AccessTokenInterface $accessToken, ClientInterface $clientStorage, array $grantTypes = array(), ClientAssertionTypeInterface $clientAssertionType = null,ScopeInterface $scopeUtil = null)57 public function __construct(AccessTokenInterface $accessToken, ClientInterface $clientStorage, array $grantTypes = array(), ?ClientAssertionTypeInterface $clientAssertionType = null, ?ScopeInterface $scopeUtil = null) 58 58 { 59 59 if (is_null($clientAssertionType)) { -
enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Request.php
r3157710 r3240587 35 35 * @api 36 36 */ 37 public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null, array $headers = null)37 public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null, ?array $headers = null) 38 38 { 39 39 $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content, $headers); … … 56 56 * @api 57 57 */ 58 public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null, array $headers = null)58 public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null, ?array $headers = null) 59 59 { 60 60 $this->request = $request; -
enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/ResponseType/AccessToken.php
r2978849 r3240587 39 39 * @endcode 40 40 */ 41 public function __construct(AccessTokenStorageInterface $tokenStorage, RefreshTokenInterface $refreshStorage = null,array $config = array())41 public function __construct(AccessTokenStorageInterface $tokenStorage, ?RefreshTokenInterface $refreshStorage = null, ?array $config = array()) 42 42 { 43 43 $this->tokenStorage = $tokenStorage; -
enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Server.php
r2978849 r3240587 151 151 * @ingroup oauth2_section_7 152 152 */ 153 public function __construct($storage = array(), array $config = array(), array $grantTypes = array(), array $responseTypes = array(), TokenTypeInterface $tokenType = null, ScopeInterface $scopeUtil = null,ClientAssertionTypeInterface $clientAssertionType = null)153 public function __construct($storage = array(), array $config = array(), array $grantTypes = array(), array $responseTypes = array(), ?TokenTypeInterface $tokenType = null, ?ScopeInterface $scopeUtil = null, ?ClientAssertionTypeInterface $clientAssertionType = null) 154 154 { 155 155 $storage = is_array($storage) ? $storage : array($storage); … … 290 290 * @see http://openid.net/specs/openid-connect-core-1_0.html#UserInfo 291 291 */ 292 public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response = null)292 public function handleUserInfoRequest(RequestInterface $request, ?ResponseInterface $response = null) 293 293 { 294 294 $this->response = is_null($response) ? new Response() : $response; … … 316 316 * @ingroup oauth2_section_4 317 317 */ 318 public function handleTokenRequest(RequestInterface $request, ResponseInterface $response = null)318 public function handleTokenRequest(RequestInterface $request, ?ResponseInterface $response = null) 319 319 { 320 320 $this->response = is_null($response) ? new Response() : $response; … … 329 329 * @return mixed 330 330 */ 331 public function grantAccessToken(RequestInterface $request, ResponseInterface $response = null)331 public function grantAccessToken(RequestInterface $request, ?ResponseInterface $response = null) 332 332 { 333 333 $this->response = is_null($response) ? new Response() : $response; … … 347 347 * @return Response|ResponseInterface 348 348 */ 349 public function handleRevokeRequest(RequestInterface $request, ResponseInterface $response = null)349 public function handleRevokeRequest(RequestInterface $request, ?ResponseInterface $response = null) 350 350 { 351 351 $this->response = is_null($response) ? new Response() : $response; … … 409 409 * @ingroup oauth2_section_3 410 410 */ 411 public function validateAuthorizeRequest(RequestInterface $request, ResponseInterface $response = null)411 public function validateAuthorizeRequest(RequestInterface $request, ?ResponseInterface $response = null) 412 412 { 413 413 $this->response = is_null($response) ? new Response() : $response; … … 423 423 * @return mixed 424 424 */ 425 public function verifyResourceRequest(RequestInterface $request, ResponseInterface $response = null, $scope = null)425 public function verifyResourceRequest(RequestInterface $request, ?ResponseInterface $response = null, $scope = null) 426 426 { 427 427 $this->response = is_null($response) ? new Response() : $response; … … 436 436 * @return mixed 437 437 */ 438 public function getAccessTokenData(RequestInterface $request, ResponseInterface $response = null)438 public function getAccessTokenData(RequestInterface $request, ?ResponseInterface $response = null) 439 439 { 440 440 $this->response = is_null($response) ? new Response() : $response;
Note: See TracChangeset
for help on using the changeset viewer.