Plugin Directory

Changeset 3240587


Ignore:
Timestamp:
02/14/2025 11:46:47 AM (3 weeks ago)
Author:
akirk
Message:

enable-mastodon-apps 1.0.0

Location:
enable-mastodon-apps/trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • enable-mastodon-apps/trunk/README.md

    r3165316 r3240587  
    77- Requires PHP: 7.4
    88- License: [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
    9 - Stable tag: 0.9.9
     9- Stable tag: 1.0.0
    1010
    1111Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance.
     
    9999## Changelog
    100100
     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
    101113### 0.9.9
    102114- Improve targeting of CORS headers ([#181])
  • enable-mastodon-apps/trunk/composer.json

    r3157710 r3240587  
    11{
    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    }
    5251}
  • enable-mastodon-apps/trunk/enable-mastodon-apps.php

    r3165316 r3240587  
    44 * Plugin author: Alex Kirk
    55 * Plugin URI: https://github.com/akirk/enable-mastodon-apps
    6  * Version: 0.9.9
     6 * Version: 1.0.0
    77 *
    88 * Description: Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance.
     
    2020defined( 'ABSPATH' ) || exit;
    2121define( 'ENABLE_MASTODON_APPS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    22 define( 'ENABLE_MASTODON_APPS_VERSION', '0.9.9' );
     22define( 'ENABLE_MASTODON_APPS_VERSION', '1.0.0' );
    2323
    2424require __DIR__ . '/vendor/bshaffer/oauth2-server-php/src/OAuth2/Autoloader.php';
  • enable-mastodon-apps/trunk/includes/class-mastodon-admin.php

    r3129164 r3240587  
    1919        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    2020        add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
     21        add_action( 'current_screen', array( $this, 'register_help' ) );
    2122    }
    2223
     
    4344    }
    4445
     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
    45112    public function process_admin() {
    46113        if ( ! current_user_can( 'edit_private_posts' ) ) {
     
    67134            case 'settings':
    68135                $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' ) );
    69138                break;
    70139            case 'debug':
     
    126195        }
    127196
     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
    128229        if ( isset( $_POST['mastodon_api_enable_debug'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
    129230            update_option( 'mastodon_api_enable_debug', true );
     
    611712        }
    612713
     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
    613726        if ( version_compare( $old_version, '0.9.1', '<' ) ) {
    614727            $comment_posts = get_posts(
  • enable-mastodon-apps/trunk/includes/class-mastodon-api.php

    r3165316 r3240587  
    3434    private $oauth;
    3535
    36     /**
    37      * The Mastodon App.
    38      *
    39      * @var Mastodon_App
    40      */
    41     private $app;
    42 
    4336    private static $last_error = false;
    4437
     
    4740    const REMAP_TAXONOMY = 'mastodon-api-remap';
    4841    const CPT            = 'enable-mastodon-apps';
     42    const POST_CPT       = 'ema-post';
    4943
    5044    /**
     
    5650        $this->register_hooks();
    5751        $this->register_taxonomy();
    58         $this->register_custom_post_type();
     52        $this->register_custom_post_types();
    5953        new Mastodon_Admin( $this->oauth );
    6054
     
    8074        add_filter( 'rest_json_encode_options', array( $this, 'rest_json_encode_options' ), 10, 2 );
    8175        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' ) );
    8378        add_filter( 'mastodon_api_mapback_user_id', array( $this, 'mapback_user_id' ) );
    8479        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' ) );
    8581    }
    8682
     
    174170    }
    175171
    176     public function register_custom_post_type() {
     172    public function register_custom_post_types() {
    177173        $args = array(
    178174            'labels'       => array(
     
    189185
    190186        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    }
    194209    public function rewrite_rules() {
    195210        $existing_rules = get_option( 'rewrite_rules' );
     
    18131828     *
    18141829     * @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     *
    18151833     * @return WP_REST_Response|\WP_HTTP_Response|\WP_Error|mixed
    18161834     */
    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
    18181840        if ( is_wp_error( $response ) && 'rest_missing_callback_param' === $response->get_error_code() ) {
    18191841            $response = new \WP_Error( $response->get_error_code(), $response->get_error_message(), array( 'status' => 422 ) );
     
    18211843
    18221844        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;
    18231871    }
    18241872
     
    21112159         * Example:
    21122160         * ```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         * } );
    21132165         * ```
    21142166         */
  • enable-mastodon-apps/trunk/includes/class-mastodon-app.php

    r3158300 r3240587  
    101101            $create_post_type = 'post';
    102102        }
    103         return apply_filters( 'mastodon_api_create_post_type', $create_post_type );
     103        return $create_post_type;
    104104    }
    105105
     
    112112            $view_post_types = array( $view_post_types );
    113113        }
    114         return apply_filters( 'mastodon_api_view_post_types', $view_post_types );
     114        return $view_post_types;
    115115    }
    116116
     
    519519                                continue;
    520520                            }
    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                            ) {
    522530                                continue;
    523531                            }
     
    651659
    652660        $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         */
    653676        $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 );
    654701
    655702        $term_id = $term['term_id'];
  • enable-mastodon-apps/trunk/includes/handler/class-handler.php

    r3129164 r3240587  
    1010namespace Enable_Mastodon_Apps\Handler;
    1111
    12 use Enable_Mastodon_Apps\Mastodon_API;
    1312use Enable_Mastodon_Apps\Mastodon_App;
    1413
     
    2625
    2726        if ( ! isset( $args['post_type'] ) ) {
    28             $post_types = array( 'post' );
     27            $post_types = array( 'post', 'comment' );
    2928            if ( $app ) {
    3029                $post_types = $app->get_view_post_types();
    3130            }
    32             $args['post_type'] = array_merge( $post_types, array( Mastodon_API::CPT ) );
     31            $args['post_type'] = $post_types;
    3332        }
    3433        $args['posts_per_page']   = $limit;
  • enable-mastodon-apps/trunk/includes/handler/class-status.php

    r3158797 r3240587  
    254254        $post_content = array_map( 'trim', $post_content );
    255255        $post_content = array_filter( $post_content );
     256        if ( empty( $post_content ) ) {
     257            return '';
     258        }
    256259        $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 -->';
    257260        return $post_content;
     
    272275
    273276        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] );
    279280        }
    280281
     
    305306                    $post_data['post_content'] .= PHP_EOL;
    306307                    $meta_json                  = array(
    307                         'id'       => $media_id,
     308                        'id'       => intval( $media_id ),
    308309                        'sizeSlug' => 'large',
    309310                    );
    310311                    $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;
    312313                    $post_data['post_content'] .= '<!-- /wp:image -->' . PHP_EOL;
    313314                } elseif ( \wp_attachment_is( 'video', $media_id ) ) {
  • enable-mastodon-apps/trunk/includes/oauth2/class-mastodon-app-storage.php

    r3129164 r3240587  
    106106            $post_formats = get_option( 'mastodon_api_default_post_formats', array() );
    107107            $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 );
    108117
    109118            $term_id = $term['term_id'];
  • enable-mastodon-apps/trunk/templates/app.php

    r3158300 r3240587  
    1414$rest_nonce  = wp_create_nonce( 'wp_rest' );
    1515$_post_types = \get_post_types( array( 'show_ui' => true ), 'objects' );
     16if ( ! 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
    1625$app         = $args['app'];
    1726$confirm     = esc_html(
     
    131140                        <p class="description">
    132141                            <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>
    133170                        </p>
    134171                    </td>
  • enable-mastodon-apps/trunk/templates/settings.php

    r3129164 r3240587  
    99    )
    1010);
     11
    1112?>
    1213
     
    2930                </tr>
    3031                <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>
    3176                    <th scope="row"><?php esc_html_e( 'Debugging', 'enable-mastodon-apps' ); ?></th>
    3277                    <td>
  • enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/ClientAssertionType/HttpBasic.php

    r2888191 r3240587  
    113113     * @ingroup oauth2_section_2
    114114     */
    115     public function getClientCredentials(RequestInterface $request, ResponseInterface $response = null)
     115    public function getClientCredentials(RequestInterface $request, ?ResponseInterface $response = null)
    116116    {
    117117        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  
    7979     * @endcode
    8080     */
    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)
    8282    {
    8383        $this->clientStorage = $clientStorage;
  • enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Controller/ResourceController.php

    r2888191 r3240587  
    4848     * @param ScopeInterface       $scopeUtil
    4949     */
    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)
    5151    {
    5252        $this->tokenType = $tokenType;
  • enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Controller/TokenController.php

    r2985283 r3240587  
    5555     * @throws InvalidArgumentException
    5656     */
    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)
    5858    {
    5959        if (is_null($clientAssertionType)) {
  • enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Request.php

    r3157710 r3240587  
    3535     * @api
    3636     */
    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)
    3838    {
    3939        $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content, $headers);
     
    5656     * @api
    5757     */
    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)
    5959    {
    6060        $this->request = $request;
  • enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/ResponseType/AccessToken.php

    r2978849 r3240587  
    3939     * @endcode
    4040     */
    41     public function __construct(AccessTokenStorageInterface $tokenStorage, RefreshTokenInterface $refreshStorage = null, array $config = array())
     41    public function __construct(AccessTokenStorageInterface $tokenStorage, ?RefreshTokenInterface $refreshStorage = null, ?array $config = array())
    4242    {
    4343        $this->tokenStorage = $tokenStorage;
  • enable-mastodon-apps/trunk/vendor/bshaffer/oauth2-server-php/src/OAuth2/Server.php

    r2978849 r3240587  
    151151     * @ingroup oauth2_section_7
    152152     */
    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)
    154154    {
    155155        $storage = is_array($storage) ? $storage : array($storage);
     
    290290     * @see http://openid.net/specs/openid-connect-core-1_0.html#UserInfo
    291291     */
    292     public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response = null)
     292    public function handleUserInfoRequest(RequestInterface $request, ?ResponseInterface $response = null)
    293293    {
    294294        $this->response = is_null($response) ? new Response() : $response;
     
    316316     * @ingroup oauth2_section_4
    317317     */
    318     public function handleTokenRequest(RequestInterface $request, ResponseInterface $response = null)
     318    public function handleTokenRequest(RequestInterface $request, ?ResponseInterface $response = null)
    319319    {
    320320        $this->response = is_null($response) ? new Response() : $response;
     
    329329     * @return mixed
    330330     */
    331     public function grantAccessToken(RequestInterface $request, ResponseInterface $response = null)
     331    public function grantAccessToken(RequestInterface $request, ?ResponseInterface $response = null)
    332332    {
    333333        $this->response = is_null($response) ? new Response() : $response;
     
    347347     * @return Response|ResponseInterface
    348348     */
    349     public function handleRevokeRequest(RequestInterface $request, ResponseInterface $response = null)
     349    public function handleRevokeRequest(RequestInterface $request, ?ResponseInterface $response = null)
    350350    {
    351351        $this->response = is_null($response) ? new Response() : $response;
     
    409409     * @ingroup oauth2_section_3
    410410     */
    411     public function validateAuthorizeRequest(RequestInterface $request, ResponseInterface $response = null)
     411    public function validateAuthorizeRequest(RequestInterface $request, ?ResponseInterface $response = null)
    412412    {
    413413        $this->response = is_null($response) ? new Response() : $response;
     
    423423     * @return mixed
    424424     */
    425     public function verifyResourceRequest(RequestInterface $request, ResponseInterface $response = null, $scope = null)
     425    public function verifyResourceRequest(RequestInterface $request, ?ResponseInterface $response = null, $scope = null)
    426426    {
    427427        $this->response = is_null($response) ? new Response() : $response;
     
    436436     * @return mixed
    437437     */
    438     public function getAccessTokenData(RequestInterface $request, ResponseInterface $response = null)
     438    public function getAccessTokenData(RequestInterface $request, ?ResponseInterface $response = null)
    439439    {
    440440        $this->response = is_null($response) ? new Response() : $response;
Note: See TracChangeset for help on using the changeset viewer.