Plugin Directory

Changeset 3104569

Timestamp:
06/19/2024 12:42:58 PM (7 weeks ago)
Author:
akirk
Message:

enable-mastodon-apps 0.9.4

Location:
enable-mastodon-apps/trunk
Files:
1 added
11 edited

Legend:

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

    r3101492 r3104569  
    77- Requires PHP: 7.4
    88- License: [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
    9 - Stable tag: 0.9.3
     9- Stable tag: 0.9.
    1010
    1111Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance.
     
    9898## Changelog
    9999
     100
     101
     102
     103
    100104### 0.9.3
    101105- Bring back the upgrade code.
     
    131135
    132136
     137
     138
    133139[#150]: https://github.com/akirk/enable-mastodon-apps/pull/150
    134140[#148]: https://github.com/akirk/enable-mastodon-apps/pull/148
  • enable-mastodon-apps/trunk/admin.css

    r3097861 r3104569  
    226226    border-color: #b32d2e;
    227227    color: #b32d2e;
     228
    228229}
    229230
     
    278279    margin: 0 auto;
    279280}
     281
     282
     283
     284
     285
     286
     287
     288
     289
     290
     291
     292
     293
     294
     295
     296
     297
     298
     299
     300
     301
     302
     303
     304
  • enable-mastodon-apps/trunk/admin.js

    r3097861 r3104569  
    3838    } );
    3939
    40     $(document).on( 'click', '.enable-mastodon-apps-settings button[name=delete-app]', function( event, response ) {
     40    $(document).on( 'click', '.enable-mastodon-apps-settings button[]', function( event, response ) {
    4141        if ( ! confirm( this.dataset.confirm ) ) {
    4242            event.preventDefault();
     
    4444        }
    4545    } );
    46 
    47     $(document).on( 'click', '.enable-mastodon-apps-settings button[name=clear-app-logs]', function( event, response ) {
    48         if ( ! confirm( this.dataset.confirm ) ) {
    49             event.preventDefault();
    50             return false;
    51         }
    52     } );
    53 
    5446} );
  • enable-mastodon-apps/trunk/enable-mastodon-apps.php

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

    r3101492 r3104569  
    5757
    5858        $tab = $_GET['tab'] ?? 'welcome';
     59
     60
     61
     62
     63
     64
     65
    5966        switch ( $tab ) {
    6067            case 'settings':
     
    7380        $this->enable_debug = get_option( 'mastodon_api_enable_debug' );
    7481        $tab = $_GET['tab'] ?? 'welcome';
     82
     83
     84
     85
     86
     87
     88
    7589        switch ( $tab ) {
    7690            case 'welcome':
     
    448462    }
    449463
     464
     465
     466
     467
     468
     469
     470
     471
     472
     473
     474
     475
     476
     477
     478
     479
     480
     481
     482
     483
     484
     485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
     510
     511
     512
     513
     514
     515
     516
     517
     518
     519
     520
     521
     522
     523
     524
     525
     526
     527
     528
     529
     530
     531
     532
     533
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
     556
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     567
     568
     569
     570
     571
     572
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
    450587    public static function upgrade_plugin( $override_old_version = false ) {
    451588        $old_version = get_option( 'ema_plugin_version' );
  • enable-mastodon-apps/trunk/includes/class-mastodon-app.php

    r3097861 r3104569  
    5555    }
    5656
    57     public function set_client_secret( $client_secret ) {
    58         return update_term_meta( $this->term->term_id, 'client_secret', $client_secret );
    59     }
    60 
    6157    public function get_redirect_uris() {
    6258        return get_term_meta( $this->term->term_id, 'redirect_uris', true );
     
    9591        return $query_args['post_formats'];
    9692    }
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
    97129
    98130    public function set_post_formats( $post_formats ) {
  • enable-mastodon-apps/trunk/includes/class-mastodon-oauth.php

    r3101476 r3104569  
    3737    public function __construct() {
    3838        $config = array(
    39             'issuer'          => home_url( '/' ),
    40             'enforce_state'   => false,
    41             'access_lifetime' => YEAR_IN_SECONDS * 2,
     39            'issuer'                     => home_url( '/' ),
     40            'enforce_state'              => false,
     41            'require_exact_redirect_uri' => false,
     42            'access_lifetime'            => YEAR_IN_SECONDS * 2,
    4243        );
    4344
  • enable-mastodon-apps/trunk/includes/handler/class-handler.php

    r3097861 r3104569  
    2222            $limit = 20;
    2323        }
    24 
     24        $app = Mastodon_App::get_current_app();
     25        $post_types = array( 'post' );
     26        if ( $app ) {
     27            $post_types = $app->get_view_post_types();
     28        }
    2529        $args['posts_per_page']   = $limit;
    26         $args['post_type']        = array( 'post', Mastodon_API::CPT );
     30        $args['post_type']        = array );
    2731        $args['suppress_filters'] = false;
    2832        $args['post_status']      = array( 'publish', 'private' );
  • enable-mastodon-apps/trunk/templates/admin-header.php

    r3097861 r3104569  
    7777    <?php
    7878}
     79
    7980?>
    8081<div class="enable-mastodon-apps-settings-header">
     
    109110</div>
    110111<hr class="wp-header-end">
     112
     113
     114
     115
     116
     117
  • enable-mastodon-apps/trunk/templates/registered-apps.php

    r3097861 r3104569  
    1313
    1414$rest_nonce = wp_create_nonce( 'wp_rest' );
    15 
    16 function post_format_select( $name, $selected = array() ) {
    17     ?>
    18         <select name="<?php echo esc_attr( $name ); ?>[]" id="<?php echo esc_attr( $name ); ?>" size="10" multiple class="appformats">
    19         <?php
    20         foreach ( get_post_format_slugs() as $format ) {
    21             ?>
    22                 <option value="<?php echo esc_attr( $format ); ?>" <?php selected( in_array( $format, $selected, true ) ); ?>><?php echo esc_html( $format ); ?></option>
    23                 <?php
    24         }
    25         ?>
    26         </select>
    27     <?php
    28 }
    2915
    3016?>
     
    5238                <th><?php esc_html_e( 'Last Used', 'enable-mastodon-apps' ); ?></th>
    5339                <th><?php esc_html_e( 'Created', 'enable-mastodon-apps' ); ?></th>
    54                 <th><?php esc_html_e( 'Actions', 'enable-mastodon-apps' ); ?></th>
    5540            </thead>
    5641            <tbody>
     
    5944                foreach ( $args['apps'] as $app ) {
    6045                    $alternate = ! $alternate;
    61                     $confirm = esc_html(
    62                         sprintf(
    63                         // translators: %s is the app name.
    64                             __( 'Are you sure you want to delete %s?', 'enable-mastodon-apps' ),
    65                             $app->get_client_name()
    66                         )
    67                     );
    6846
    6947                    ?>
    7048                    <tr id='app-<?php echo esc_attr( $app->get_client_id() ); ?>' class="<?php echo $alternate ? 'alternate' : ''; ?>">
    7149                        <td title='<?php echo esc_attr( $app->get_client_id() ); ?>'>
     50
    7251                            <?php
    73                             if ( $app->get_website() ) {
    74                                 ?>
    75                                 <a href="<?php echo esc_url( $app->get_website() ); ?>"><?php echo esc_html( $app->get_client_name() ); ?></a>
    76                                 <?php
    77                             } else {
    78                                 echo esc_html( $app->get_client_name() );
    79                             }
    8052
    8153                            if ( $app->is_outdated() && Mastodon_App::DEBUG_CLIENT_ID !== $app->get_client_id() ) {
     
    8759                        <td><?php echo esc_html( $app->get_scopes() ); ?></td>
    8860                        <td class="debug-hide">
    89                             <details>
    90                                 <summary><?php echo esc_html( implode( ', ', $app->get_post_formats() ) ); ?></summary>
    91                                 <?php post_format_select( 'app_post_formats[' . $app->get_client_id() . ']', $app->get_post_formats() ); ?>
    92                             </details>
     61                            <?php
     62                            foreach ( get_post_format_strings() as $format => $label ) {
     63                                if ( in_array( $format, $app->get_post_formats() ) ) {
     64                                    echo esc_html( $label ) . '<br>';
     65                                }
     66                            }
     67                            ?>
    9368                        </td>
    9469                            <?php td_timestamp( $app->get_last_used() ); ?>
    9570                            <?php td_timestamp( $app->get_creation_date() ); ?>
    96                         <td>
    97                             <button name="save-app" value="<?php echo esc_attr( $app->get_client_id() ); ?>" class="button save-app button-secondary"><?php esc_html_e( 'Save' ); /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ ?></button>
    98                             <button name="delete-app" data-confirm="<?php echo esc_attr( $confirm ); ?>" value="<?php echo esc_attr( $app->get_client_id() ); ?>" class="button button-destructive"><?php esc_html_e( 'Delete' ); /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ ?></button>
    99                         </td>
    10071                    </tr>
    10172                    <?php
    102                     if ( $args['enable_debug'] ) {
    103                         $last_requests = $app->get_last_requests();
    104                         if ( $last_requests ) {
    105                             $confirm = esc_html(
    106                                 sprintf(
    107                                 // translators: %s is the app name.
    108                                     __( 'Are you sure you want to delete all logs for %s?', 'enable-mastodon-apps' ),
    109                                     $app->get_client_name()
    110                                 )
    111                             );
    112                             ?>
    113                             <tr id='applog-<?php echo esc_attr( $app->get_client_id() ); ?>' class="<?php echo $alternate ? 'alternate' : ''; ?>">
    114                                 <td colspan="6">
    115                                     <details class="tt"><summary>
    116                                     <?php
    117                                     echo esc_html(
    118                                         sprintf(
    119                                             // translators: %ds is the number of requests.
    120                                             _n( '%d logged request', '%d logged requests', count( $last_requests ), 'enable-mastodon-apps' ),
    121                                             count( $last_requests )
    122                                         )
    123                                     );
    124                                     ?>
    125                                     </summary>
    126                                             <?php
    127                                             foreach ( $last_requests as $request ) {
    128                                                 output_request_log( $request, $rest_nonce );
    129                                             }
    130                                             ?>
    131                                     </details>
    132                                 </td>
    133                                 <td>
    134                                     <button name="clear-app-logs" data-confirm="<?php echo esc_attr( $confirm ); ?>" value="<?php echo esc_attr( $app->get_client_id() ); ?>" class="button button-destructive"><?php esc_html_e( 'Clear logs', 'enable-mastodon-apps' ); ?></button>
    135                                 </td>
    136                             </tr>
    137                             <?php
    138                         }
    139                     }
    14073                }
    14174                ?>
     
    14376        </table>
    14477
    145         <?php if ( $args['enable_debug'] ) : ?>
     78    <?php if ( $args['enable_debug'] ) : ?>
     79        <?php if ( ! empty( $args['codes'] ) ) : ?>
    14680            <h2><?php esc_html_e( 'Authorization Codes', 'enable-mastodon-apps' ); ?></h2>
    14781
     
    16397                    <th><?php esc_html_e( 'Expires', 'enable-mastodon-apps' ); ?></th>
    16498                    <th><?php esc_html_e( 'Scope', 'enable-mastodon-apps' ); ?></th>
    165                     <th><?php esc_html_e( 'Actions', 'enable-mastodon-apps' ); ?></th>
    16699                </thead>
    167100                <tbody>
     
    190123                            <?php td_timestamp( $data['expires'] ); ?>
    191124                            <td><?php echo esc_html( $data['scope'] ); ?></td>
    192                             <td><button name="delete-code" value="<?php echo esc_attr( $code ); ?>" class="button button-destructive"><?php esc_html_e( 'Delete' ); /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ ?></button></td>
    193125                        </tr>
    194126                        <?php
     
    197129                </tbody>
    198130            </table>
     131
    199132
    200             <h2><?php esc_html_e( 'Access Tokens', 'enable-mastodon-apps' ); ?></h2>
    201             <span class="count">
    202                 <?php
    203                 echo esc_html(
    204                     sprintf(
    205                         // translators: %d is the number of tokens.
    206                         _n( '%d token', '%d tokens', count( $args['tokens'] ), 'enable-mastodon-apps' ),
    207                         count( $args['tokens'] )
    208                     )
    209                 );
    210                 ?>
    211             </span>
    212             <table class="widefat striped">
    213                 <thead>
    214                     <th><?php esc_html_e( 'App', 'enable-mastodon-apps' ); ?></th>
    215                     <th><?php esc_html_e( 'User', 'enable-mastodon-apps' ); ?></th>
    216                     <th><?php esc_html_e( 'Last Used', 'enable-mastodon-apps' ); ?></th>
    217                     <th><?php esc_html_e( 'Expires', 'enable-mastodon-apps' ); ?></th>
    218                     <th><?php esc_html_e( 'Scope', 'enable-mastodon-apps' ); ?></th>
    219                     <th><?php esc_html_e( 'Actions', 'enable-mastodon-apps' ); ?></th>
    220                 </thead>
    221                 <tbody>
    222                     <?php
    223                     foreach ( $args['tokens'] as $token => $data ) {
    224                         $user = 'app-level';
    225                         if ( $data['user_id'] ) {
    226                             $userdata = get_user_by( 'ID', $data['user_id'] );
    227                             if ( $userdata ) {
    228                                 if ( is_wp_error( $userdata ) ) {
    229                                     $user = $userdata->get_error_message();
    230                                 } else {
    231                                     $user = $userdata->user_login;
    232                                 }
    233                             } else {
    234                                 $user = 'error';
    235                             }
    236                         }
    237                         ?>
    238                         <tr id="token-<?php echo esc_attr( $token ); ?>">
    239                             <td title="<?php echo esc_attr( $token ); ?>">
    240                                 <?php
    241                                 if ( isset( $args['apps'][ $data['client_id'] ] ) ) {
    242                                     ?>
    243                                     <a href="#app-<?php echo esc_attr( $data['client_id'] ); ?>"><?php echo esc_html( $args['apps'][ $data['client_id'] ]->get_client_name() ); ?></a>
    244                                     <?php
    245                                 } else {
    246                                     echo esc_html(
    247                                         sprintf(
    248                                         // Translators: %s is the app ID.
    249                                             __( 'Unknown App: %s', 'enable-mastodon-apps' ),
    250                                             $data['client_id']
    251                                         )
    252                                     );
    253                                     echo ' <span class="pill pill-outdated" title="' . esc_html__( 'Associated with an app that no longer exists.', 'enable-mastodon-apps' ) . '">' . esc_html__( 'Outdated', 'enable-mastodon-apps' ) . '</span>';
    254                                 }
    255                                 ?>
    256                             </td>
    257                             <td><?php echo esc_html( $user ); ?></td>
    258                             <?php td_timestamp( $data['last_used'] ); ?>
    259                             <?php td_timestamp( $data['expires'], true ); ?>
    260                             <td><?php echo esc_html( $data['scope'] ); ?></td>
    261                             <td><button name="delete-token" value="<?php echo esc_attr( $token ); ?>" class="button button-destructive"><?php esc_html_e( 'Delete' ); /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ ?></button></td>
    262                         </tr>
    263                         <?php
    264                     }
    265                     ?>
    266                 </tbody>
    267             </table>
    268 
    269             <?php if ( ! empty( $args['codes'] ) || ! empty( $args['tokens'] ) || ! empty( $args['apps'] ) ) : ?>
    270                 <h2><?php esc_html_e( 'Cleanup', 'enable-mastodon-apps' ); ?></h2>
    271                 <button name="delete-outdated" class="button"><?php esc_html_e( 'Delete outdated apps and tokens', 'enable-mastodon-apps' ); ?></button>
    272                 <button name="delete-never-used" class="button"><?php esc_html_e( 'Delete never used apps and tokens', 'enable-mastodon-apps' ); ?></button>
    273                 <button name="delete-apps-without-tokens" class="button"><?php esc_html_e( 'Delete apps without tokens', 'enable-mastodon-apps' ); ?></button>
    274                 <button name="clear-all-app-logs" class="button button-destructive"><?php esc_html_e( 'Clear all logs', 'enable-mastodon-apps' ); ?></button>
     133        <?php if ( ! empty( $args['codes'] ) || ! empty( $args['tokens'] ) || ! empty( $args['apps'] ) ) : ?>
     134            <h2><?php esc_html_e( 'Cleanup', 'enable-mastodon-apps' ); ?></h2>
     135            <button name="delete-outdated" class="button"><?php esc_html_e( 'Delete outdated apps and tokens', 'enable-mastodon-apps' ); ?></button>
     136            <button name="delete-never-used" class="button"><?php esc_html_e( 'Delete never used apps and tokens', 'enable-mastodon-apps' ); ?></button>
     137            <button name="delete-apps-without-tokens" class="button"><?php esc_html_e( 'Delete apps without tokens', 'enable-mastodon-apps' ); ?></button>
     138            <button name="clear-all-app-logs" class="button button-destructive"><?php esc_html_e( 'Clear all logs', 'enable-mastodon-apps' ); ?></button>
    275139        <?php endif; ?>
    276140    <?php endif; ?>
    277 </form>
     141</form>
    278142</div>
  • enable-mastodon-apps/trunk/templates/welcome.php

    r3101476 r3104569  
    4747        </p>
    4848        <p>
    49             <?php esc_html_e( 'Since the task of this plugin to achieve Mastodon API compatibility is complex, it is possible that you encounter issues.', 'enable-mastodon-apps' ); ?>
     49            <span><?php esc_html_e( 'Since the task of this plugin to achieve Mastodon API compatibility is complex, it is possible that you encounter issues.', 'enable-mastodon-apps' ); ?></span>
     50            <span>
    5051            <?php
    5152                echo wp_kses(
     
    6364                );
    6465                ?>
     66
    6567        </p>
    6668    </div>
Note: See TracChangeset for help on using the changeset viewer.