Plugin Directory

Changeset 1704036


Ignore:
Timestamp:
07/27/2017 08:54:34 PM (9 years ago)
Author:
kernox
Message:

Add picture support on toot

Location:
wp-mastodon-share/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-mastodon-share/trunk/tootophp/TootoPHP.php

    r1702506 r1704036  
    287287                'status' => $content,
    288288                'visibility' => $visibility,
    289                 'media_ids' => $medias
     289                'media_ids[]' => $medias
    290290            ]
    291291        );
  • wp-mastodon-share/trunk/wp-mastodon-share.php

    r1702686 r1704036  
    55 * Plugin URI: https://github.com/kernox/mastoshare-wp
    66 * Description: Share WordPress posts on a mastodon instance.
    7  * Version: 0.6
     7 * Version: 0.7
    88 * Author: Hellexis
    99 * Author URI: https://github.com/kernox
     
    6363        $is_valid_nonce = wp_verify_nonce( $_POST['_wpnonce'], 'mastoshare-configuration' );
    6464
    65         if ( $is_valid_nonce ) {
     65        if ( $is_valid_nonce ) {           
     66            $instance = get_option( 'mastoshare-instance' );
    6667            $message = $_POST['message'];
     68            $token = sanitize_key( $_POST['token'] );
     69
     70            $tooto_php = new TootoPHP\TootoPHP( $instance );
     71            $app = $tooto_php->registerApp( 'Mastodon Share for WP', 'http://www.github.com/kernox' );
     72           
     73            if($token != get_option('mastoshare-token')){
     74                $app->registerAccessToken( trim( $token ) );
     75
     76                //Force the token fetch
     77                $profile = $app->getUser();
     78            }
     79
    6780            update_option( 'mastoshare-message', sanitize_textarea_field( $message ) );
    68             update_option( 'mastoshare-token', sanitize_key( $_POST['token'] ) );
     81            update_option( 'mastoshare-token', $token );
    6982            update_option( 'mastoshare-mode', sanitize_text_field( $_POST['mode'] ) );
    7083            update_option( 'mastoshare-toot-size', (int) $_POST['size'] );
     
    132145
    133146    $post = get_post( $id );
     147    $thumb_url = get_the_post_thumbnail_url($id);
     148   
    134149    $toot_size = (int) get_option( 'mastoshare-toot-size', 500 );
    135150
     
    146161            $app = $tooto_php->registerApp( 'Mastodon Share for WP', 'http://www.github.com/kernox' );
    147162
    148             $token = get_option( 'mastoshare-token' );
    149 
    150             $app->registerAccessToken( trim( $token ) );
    151 
    152163            $mode = get_option( 'mastoshare-mode', 'public' );
    153             $toot = $app->postStatus( $message, $mode );
     164
     165            $medias = array();
     166
     167            if ( $thumb_url ) {
     168
     169                $thumb_path = str_replace(get_site_url(), get_home_path(), $thumb_url);
     170
     171                $attachment = $app->createAttachement( $thumb_path );
     172
     173                $media = $attachment['id'];
     174            }
     175           
     176            $toot = $app->postStatus( $message, $mode, $media);
    154177
    155178            update_post_meta( $post->ID, 'mastoshare-post-status', 'off' );
     
    160183                    serialize(
    161184                        array(
    162                             'message' => 'Mastodon Share: ' . __( 'Sorry, can\'t send toot !', 'wp-mastodon-share' ) .
     185                            'message' => '<strong>Mastodon Share</strong> : ' . __( 'Sorry, can\'t send toot !', 'wp-mastodon-share' ) .
    163186                            '<p><strong>' . __( 'Instance message', 'wp-mastodon-share' ) . '</strong> : ' . $toot['error'] . '</p>',
    164187                            'class' => 'error',
     
    171194                    serialize(
    172195                        array(
    173                             'message' => 'Mastodon Share: ' . __( 'Toot successfully sent !', 'wp-mastodon-share' ),
     196                            'message' => '<strong>Mastodon Share</strong> : ' . __( 'Toot successfully sent !', 'wp-mastodon-share' ),
    174197                            'class' => 'success',
    175198                        )
     
    192215
    193216    if ( is_array( $notice ) ) {
    194         echo '<div class="notice notice-' . sanitize_html_class( $notice['class'] ) . ' is-dismissible"><p>' . esc_html( $notice['message'] ) . '</p></div>';
     217        echo '<div class="notice notice-' . sanitize_html_class( $notice['class'] ) . ' is-dismissible"><p>' . $notice['message'] . '</p></div>';
    195218        update_option( 'mastoshare-notice', null );
    196219    }
Note: See TracChangeset for help on using the changeset viewer.