Plugin Directory

Changeset 2903429


Ignore:
Timestamp:
04/24/2023 04:43:03 PM (3 years ago)
Author:
antonlukin
Message:

Update to version 1.1.12 from GitHub

Location:
social-planner
Files:
22 edited
1 copied

Legend:

Unmodified
Added
Removed
  • social-planner/assets/banner-1544x500.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • social-planner/assets/banner-772x250.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • social-planner/assets/icon-128x128.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • social-planner/assets/icon-256x256.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • social-planner/assets/screenshot-1.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • social-planner/assets/screenshot-2.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • social-planner/assets/screenshot-3.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • social-planner/assets/screenshot-4.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • social-planner/tags/1.1.12/networks/class-network-facebook.php

    r2699801 r2903429  
    152152        $body['message'] = $excerpt;
    153153
     154        /**
     155         * Filter request body arguments using message data.
     156         *
     157         * @param string $body    Request body arguments.
     158         * @param array  $message Message data.
     159         * @param string $network Network name.
     160         *
     161         * @since 1.1.12
     162         */
     163        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
     164
    154165        return self::send_request( $url . '/feed', $body );
    155166    }
     
    270281        }
    271282
     283        /**
     284         * Filter request arguments right before sending.
     285         *
     286         * @param string $args    Request arguments.
     287         * @param array  $url     URL to retrieve.
     288         * @param string $network Network name.
     289         *
     290         * @since 1.1.12
     291         */
     292        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     293
    272294        return wp_remote_post( $url, $args );
    273295    }
  • social-planner/tags/1.1.12/networks/class-network-ok.php

    r2699801 r2903429  
    185185        $body['access_token'] = $settings['access_token'];
    186186
     187        /**
     188         * Filter request body arguments using message data.
     189         *
     190         * @param string $body    Request body arguments.
     191         * @param array  $message Message data.
     192         * @param string $network Network name.
     193         *
     194         * @since 1.1.12
     195         */
     196        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
     197
    187198        return self::send_request( $url, $body );
    188199    }
     
    398409        }
    399410
     411        /**
     412         * Filter request arguments right before sending.
     413         *
     414         * @param string $args    Request arguments.
     415         * @param array  $url     URL to retrieve.
     416         * @param string $network Network name.
     417         *
     418         * @since 1.1.12
     419         */
     420        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     421
    400422        return wp_remote_post( $url, $args );
    401423    }
  • social-planner/tags/1.1.12/networks/class-network-telegram.php

    r2699801 r2903429  
    165165        $body['text'] = $excerpt;
    166166
     167        /**
     168         * Filter request body arguments using message data.
     169         *
     170         * @param string $body    Request body arguments.
     171         * @param array  $message Message data.
     172         * @param string $network Network name.
     173         *
     174         * @since 1.1.12
     175         */
     176        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
     177
    167178        return self::send_request( $url . '/sendMessage', $body );
    168179    }
     
    196207
    197208        return self::send_request( $url . '/sendPhoto', $body, $headers );
     209    }
     210
     211    /**
     212     * Create multipart data.
     213     *
     214     * @param array  $data     List of default query params.
     215     * @param array  $files    List of files.
     216     * @param string $boundary Boundary delimiter.
     217     */
     218    private static function prepare_multipart_data( $data, $files, $boundary ) {
     219        $body = array();
     220
     221        foreach ( $data as $key => $value ) {
     222            $body[] = "--$boundary";
     223            $body[] = "Content-Disposition: form-data; name=\"$key\"";
     224            $body[] = "\r\n" . $value;
     225        }
     226
     227        foreach ( $files as $name => $filename ) {
     228            $file = basename( $filename );
     229            $type = wp_check_filetype( $filename )['type'];
     230
     231            // phpcs:ignore WordPress.WP.AlternativeFunctions
     232            $content = file_get_contents( $filename );
     233
     234            if ( false === $content ) {
     235                return new WP_Error( 'sending', esc_html__( 'Cannot read poster file' ) );
     236            }
     237
     238            $body[] = "--$boundary";
     239            $body[] = "Content-Disposition: form-data; name=\"$name\"; filename=\"$file\"";
     240            $body[] = "Content-Type: $type";
     241            $body[] = "\r\n" . $content;
     242        }
     243
     244        // Add final boundary.
     245        $body[] = "--$boundary--\r\n";
     246
     247        return implode( "\r\n", $body );
     248    }
     249
     250    /**
     251     * Prepare message excerpt.
     252     *
     253     * @param array $message List of message args.
     254     */
     255    private static function prepare_message_excerpt( $message ) {
     256        $excerpt = array();
     257
     258        if ( ! empty( $message['excerpt'] ) ) {
     259            $message['excerpt'] = preg_replace( '/\*(.+?)\*/s', '<b>$1</b>', $message['excerpt'] );
     260            $message['excerpt'] = preg_replace( '/_(.+?)_/s', '<i>$1</i>', $message['excerpt'] );
     261
     262            $excerpt[] = $message['excerpt'];
     263        }
     264
     265        if ( ! empty( $message['link'] ) ) {
     266            $excerpt[] = $message['link'];
     267        }
     268
     269        $excerpt = implode( "\n\n", $excerpt );
     270
     271        /**
     272         * Filter message excerpt right before sending.
     273         *
     274         * @param string $excerpt Message excerpt.
     275         * @param array  $message Original message array.
     276         * @param string $network Network name.
     277         */
     278        return apply_filters( 'social_planner_prepare_excerpt', $excerpt, $message, self::NETWORK_NAME );
    198279    }
    199280
     
    216297        }
    217298
     299        /**
     300         * Filter request arguments right before sending.
     301         *
     302         * @param string $args    Request arguments.
     303         * @param array  $url     URL to retrieve.
     304         * @param string $network Network name.
     305         *
     306         * @since 1.1.12
     307         */
     308        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     309
    218310        return wp_remote_post( $url, $args );
    219311    }
    220 
    221     /**
    222      * Create multipart data.
    223      *
    224      * @param array  $data     List of default query params.
    225      * @param array  $files    List of files.
    226      * @param string $boundary Boundary delimiter.
    227      */
    228     private static function prepare_multipart_data( $data, $files, $boundary ) {
    229         $body = array();
    230 
    231         foreach ( $data as $key => $value ) {
    232             $body[] = "--$boundary";
    233             $body[] = "Content-Disposition: form-data; name=\"$key\"";
    234             $body[] = "\r\n" . $value;
    235         }
    236 
    237         foreach ( $files as $name => $filename ) {
    238             $file = basename( $filename );
    239             $type = wp_check_filetype( $filename )['type'];
    240 
    241             // phpcs:ignore WordPress.WP.AlternativeFunctions
    242             $content = file_get_contents( $filename );
    243 
    244             if ( false === $content ) {
    245                 return new WP_Error( 'sending', esc_html__( 'Cannot read poster file' ) );
    246             }
    247 
    248             $body[] = "--$boundary";
    249             $body[] = "Content-Disposition: form-data; name=\"$name\"; filename=\"$file\"";
    250             $body[] = "Content-Type: $type";
    251             $body[] = "\r\n" . $content;
    252         }
    253 
    254         // Add final boundary.
    255         $body[] = "--$boundary--\r\n";
    256 
    257         return implode( "\r\n", $body );
    258     }
    259 
    260     /**
    261      * Prepare message excerpt.
    262      *
    263      * @param array $message List of message args.
    264      */
    265     private static function prepare_message_excerpt( $message ) {
    266         $excerpt = array();
    267 
    268         if ( ! empty( $message['excerpt'] ) ) {
    269             $message['excerpt'] = preg_replace( '/\*(.+?)\*/s', '<b>$1</b>', $message['excerpt'] );
    270             $message['excerpt'] = preg_replace( '/_(.+?)_/s', '<i>$1</i>', $message['excerpt'] );
    271 
    272             $excerpt[] = $message['excerpt'];
    273         }
    274 
    275         if ( ! empty( $message['link'] ) ) {
    276             $excerpt[] = $message['link'];
    277         }
    278 
    279         $excerpt = implode( "\n\n", $excerpt );
    280 
    281         /**
    282          * Filter message excerpt right before sending.
    283          *
    284          * @param string $excerpt Message excerpt.
    285          * @param array  $message Original message array.
    286          * @param string $network Network name.
    287          */
    288         return apply_filters( 'social_planner_prepare_excerpt', $excerpt, $message, self::NETWORK_NAME );
    289     }
    290312}
  • social-planner/tags/1.1.12/networks/class-network-twitter.php

    r2699801 r2903429  
    181181        );
    182182
     183        /**
     184         * Filter request body arguments using message data.
     185         *
     186         * @param string $body    Request body arguments.
     187         * @param array  $message Message data.
     188         * @param string $network Network name.
     189         *
     190         * @since 1.1.12
     191         */
     192        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
     193
    183194        return self::send_request( $url, $body, $headers );
    184195    }
     
    233244
    234245    /**
     246     * Create multipart data.
     247     *
     248     * @param string $path     Path to local file.
     249     * @param string $name     Name of body parameter.
     250     * @param string $boundary Boundary delimiter.
     251     */
     252    private static function prepare_multipart_data( $path, $name, $boundary ) {
     253        $file = basename( $path );
     254        $type = wp_check_filetype( $path )['type'];
     255
     256        // phpcs:ignore WordPress.WP.AlternativeFunctions
     257        $content = file_get_contents( $path );
     258
     259        if ( false === $content ) {
     260            return new WP_Error( 'sending', esc_html__( 'Cannot read poster file', 'social-planner' ) );
     261        }
     262
     263        $body[] = "--$boundary";
     264        $body[] = "Content-Disposition: form-data; name=\"$name\"; filename=\"$file\"";
     265        $body[] = "Content-Type: $type";
     266        $body[] = "\r\n" . $content;
     267        $body[] = "--$boundary--\r\n";
     268
     269        return implode( "\r\n", $body );
     270    }
     271
     272    /**
     273     * Create status from message object.
     274     *
     275     * @param array $message List of message args.
     276     */
     277    private static function prepare_message_excerpt( $message ) {
     278        $excerpt = array();
     279
     280        if ( ! empty( $message['excerpt'] ) ) {
     281            $excerpt[] = $message['excerpt'];
     282        }
     283
     284        if ( ! empty( $message['link'] ) ) {
     285            $excerpt[] = $message['link'];
     286        }
     287
     288        $excerpt = implode( "\n\n", $excerpt );
     289
     290        /**
     291         * Filter message excerpt right before sending.
     292         *
     293         * @param string $excerpt Message excerpt.
     294         * @param array  $message Original message array.
     295         * @param string $network Network name.
     296         */
     297        return apply_filters( 'social_planner_prepare_excerpt', $excerpt, $message, self::NETWORK_NAME );
     298    }
     299
     300    /**
     301     * Generate OAuth signature.
     302     *
     303     * @param string $url API endpoint.
     304     * @param string $secret Generated secret.
     305     * @param array  $fields List of query arguments.
     306     */
     307    private static function get_oauth_signature( $url, $secret, $fields ) {
     308        ksort( $fields );
     309
     310        $values = array();
     311
     312        foreach ( $fields as $key => $value ) {
     313            $values[] = "$key=" . rawurlencode( $value );
     314        }
     315
     316        $base = 'POST&' . rawurlencode( $url ) . '&' . rawurlencode( implode( '&', $values ) );
     317
     318        // phpcs:ignore
     319        return base64_encode( hash_hmac( 'sha1', $base, $secret, true ) );
     320    }
     321
     322    /**
     323     * Build OAuth header.
     324     *
     325     * @param array $fields List of header arguments.
     326     */
     327    private static function build_oauth_header( $fields ) {
     328        $values = array();
     329
     330        foreach ( $fields as $key => $value ) {
     331            $values[] = $key . '="' . rawurlencode( $value ) . '"';
     332        }
     333
     334        return 'OAuth ' . implode( ', ', $values );
     335    }
     336
     337    /**
    235338     * Send request to remote server.
    236339     *
     
    250353        }
    251354
     355        /**
     356         * Filter request arguments right before sending.
     357         *
     358         * @param string $args    Request arguments.
     359         * @param array  $url     URL to retrieve.
     360         * @param string $network Network name.
     361         *
     362         * @since 1.1.12
     363         */
     364        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     365
    252366        return wp_remote_post( $url, $args );
    253367    }
    254 
    255     /**
    256      * Create multipart data.
    257      *
    258      * @param string $path     Path to local file.
    259      * @param string $name     Name of body parameter.
    260      * @param string $boundary Boundary delimiter.
    261      */
    262     private static function prepare_multipart_data( $path, $name, $boundary ) {
    263         $file = basename( $path );
    264         $type = wp_check_filetype( $path )['type'];
    265 
    266         // phpcs:ignore WordPress.WP.AlternativeFunctions
    267         $content = file_get_contents( $path );
    268 
    269         if ( false === $content ) {
    270             return new WP_Error( 'sending', esc_html__( 'Cannot read poster file', 'social-planner' ) );
    271         }
    272 
    273         $body[] = "--$boundary";
    274         $body[] = "Content-Disposition: form-data; name=\"$name\"; filename=\"$file\"";
    275         $body[] = "Content-Type: $type";
    276         $body[] = "\r\n" . $content;
    277         $body[] = "--$boundary--\r\n";
    278 
    279         return implode( "\r\n", $body );
    280     }
    281 
    282     /**
    283      * Create status from message object.
    284      *
    285      * @param array $message List of message args.
    286      */
    287     private static function prepare_message_excerpt( $message ) {
    288         $excerpt = array();
    289 
    290         if ( ! empty( $message['excerpt'] ) ) {
    291             $excerpt[] = $message['excerpt'];
    292         }
    293 
    294         if ( ! empty( $message['link'] ) ) {
    295             $excerpt[] = $message['link'];
    296         }
    297 
    298         $excerpt = implode( "\n\n", $excerpt );
    299 
    300         /**
    301          * Filter message excerpt right before sending.
    302          *
    303          * @param string $excerpt Message excerpt.
    304          * @param array  $message Original message array.
    305          * @param string $network Network name.
    306          */
    307         return apply_filters( 'social_planner_prepare_excerpt', $excerpt, $message, self::NETWORK_NAME );
    308     }
    309 
    310     /**
    311      * Generate OAuth signature.
    312      *
    313      * @param string $url API endpoint.
    314      * @param string $secret Generated secret.
    315      * @param array  $fields List of query arguments.
    316      */
    317     private static function get_oauth_signature( $url, $secret, $fields ) {
    318         ksort( $fields );
    319 
    320         $values = array();
    321 
    322         foreach ( $fields as $key => $value ) {
    323             $values[] = "$key=" . rawurlencode( $value );
    324         }
    325 
    326         $base = 'POST&' . rawurlencode( $url ) . '&' . rawurlencode( implode( '&', $values ) );
    327 
    328         // phpcs:ignore
    329         return base64_encode( hash_hmac( 'sha1', $base, $secret, true ) );
    330     }
    331 
    332     /**
    333      * Build OAuth header.
    334      *
    335      * @param array $fields List of header arguments.
    336      */
    337     private static function build_oauth_header( $fields ) {
    338         $values = array();
    339 
    340         foreach ( $fields as $key => $value ) {
    341             $values[] = $key . '="' . rawurlencode( $value ) . '"';
    342         }
    343 
    344         return 'OAuth ' . implode( ', ', $values );
    345     }
    346368}
  • social-planner/tags/1.1.12/networks/class-network-vk.php

    r2699801 r2903429  
    159159        );
    160160
    161         $url = 'https://api.vk.com/method/wall.post';
     161        /**
     162         * Filter request body arguments using message data.
     163         *
     164         * @param string $body    Request body arguments.
     165         * @param array  $message Message data.
     166         * @param string $network Network name.
     167         *
     168         * @since 1.1.12
     169         */
     170        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
    162171
    163172        // Publish message.
    164         return self::send_request( $url, $body );
     173        return self::send_request( 'https://api.vk.com/method/wall.post', $body );
    165174    }
    166175
     
    192201        }
    193202
    194         $url = 'https://api.vk.com/method/photos.saveWallPhoto';
    195 
    196203        // Save image to VK.com wall.
    197         $response = self::send_request( $url, array_merge( $body, $options ) );
     204        $response = self::send_request( 'https://api.vk.com/method/photos.saveWallPhoto', array_merge( $body, $options ) );
    198205
    199206        if ( is_wp_error( $response ) ) {
     
    262269     */
    263270    private static function get_upload_server( $body ) {
    264         $url = 'https://api.vk.com/method/photos.getWallUploadServer';
    265 
    266271        // Try to get VK wall upload server.
    267         $response = self::send_request( $url, $body );
     272        $response = self::send_request( 'https://api.vk.com/method/photos.getWallUploadServer', $body );
    268273
    269274        if ( is_wp_error( $response ) ) {
     
    369374        }
    370375
     376        /**
     377         * Filter request arguments right before sending.
     378         *
     379         * @param string $args    Request arguments.
     380         * @param array  $url     URL to retrieve.
     381         * @param string $network Network name.
     382         *
     383         * @since 1.1.12
     384         */
     385        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     386
    371387        return wp_remote_post( $url, $args );
    372388    }
  • social-planner/tags/1.1.12/readme.txt

    r2839003 r2903429  
    44Tags: automation, autopost, auto-post, auto post, socialnetworks, socialnetwork, social networks, social network, facebook, twitter, telegram, vkontakte, vk.com, ok.ru, api, social images, social image, sharing, share, repost, re-post, open graph
    55Requires at least: 5.3
    6 Tested up to: 6.1
    7 Stable tag: 1.1.11
     6Tested up to: 6.2
     7Stable tag: 1.1.12
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    5151== Changelog ==
    5252
     53= 1.1.12 =
     54* Adding `social_planner_before_request` and `social_planner_filter_request_body` filters for each network class
     55
    5356= 1.1.11 =
    5457* Fixing `subscribeOnSaving` error on Post editor while using Classic Editor
  • social-planner/tags/1.1.12/social-planner.php

    r2839003 r2903429  
    88 * Requires at least: 5.3
    99 * Tested up to: 5.8
    10  * Version: 1.1.11
     10 * Version: 1.1.12
    1111 *
    1212 * Text Domain: social-planner
     
    2929 * Plugin version.
    3030 */
    31 define( 'SOCIAL_PLANNER_VERSION', '1.1.11' );
     31define( 'SOCIAL_PLANNER_VERSION', '1.1.12' );
    3232
    3333/**
     
    4444 * Shortcut constant to the path of this file.
    4545 */
    46 define( 'SOCIAL_PLANNER_DIR', dirname( __FILE__ ) );
     46define( 'SOCIAL_PLANNER_DIR', __DIR__ );
    4747
    4848/**
  • social-planner/trunk/networks/class-network-facebook.php

    r2699801 r2903429  
    152152        $body['message'] = $excerpt;
    153153
     154        /**
     155         * Filter request body arguments using message data.
     156         *
     157         * @param string $body    Request body arguments.
     158         * @param array  $message Message data.
     159         * @param string $network Network name.
     160         *
     161         * @since 1.1.12
     162         */
     163        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
     164
    154165        return self::send_request( $url . '/feed', $body );
    155166    }
     
    270281        }
    271282
     283        /**
     284         * Filter request arguments right before sending.
     285         *
     286         * @param string $args    Request arguments.
     287         * @param array  $url     URL to retrieve.
     288         * @param string $network Network name.
     289         *
     290         * @since 1.1.12
     291         */
     292        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     293
    272294        return wp_remote_post( $url, $args );
    273295    }
  • social-planner/trunk/networks/class-network-ok.php

    r2699801 r2903429  
    185185        $body['access_token'] = $settings['access_token'];
    186186
     187        /**
     188         * Filter request body arguments using message data.
     189         *
     190         * @param string $body    Request body arguments.
     191         * @param array  $message Message data.
     192         * @param string $network Network name.
     193         *
     194         * @since 1.1.12
     195         */
     196        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
     197
    187198        return self::send_request( $url, $body );
    188199    }
     
    398409        }
    399410
     411        /**
     412         * Filter request arguments right before sending.
     413         *
     414         * @param string $args    Request arguments.
     415         * @param array  $url     URL to retrieve.
     416         * @param string $network Network name.
     417         *
     418         * @since 1.1.12
     419         */
     420        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     421
    400422        return wp_remote_post( $url, $args );
    401423    }
  • social-planner/trunk/networks/class-network-telegram.php

    r2699801 r2903429  
    165165        $body['text'] = $excerpt;
    166166
     167        /**
     168         * Filter request body arguments using message data.
     169         *
     170         * @param string $body    Request body arguments.
     171         * @param array  $message Message data.
     172         * @param string $network Network name.
     173         *
     174         * @since 1.1.12
     175         */
     176        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
     177
    167178        return self::send_request( $url . '/sendMessage', $body );
    168179    }
     
    196207
    197208        return self::send_request( $url . '/sendPhoto', $body, $headers );
     209    }
     210
     211    /**
     212     * Create multipart data.
     213     *
     214     * @param array  $data     List of default query params.
     215     * @param array  $files    List of files.
     216     * @param string $boundary Boundary delimiter.
     217     */
     218    private static function prepare_multipart_data( $data, $files, $boundary ) {
     219        $body = array();
     220
     221        foreach ( $data as $key => $value ) {
     222            $body[] = "--$boundary";
     223            $body[] = "Content-Disposition: form-data; name=\"$key\"";
     224            $body[] = "\r\n" . $value;
     225        }
     226
     227        foreach ( $files as $name => $filename ) {
     228            $file = basename( $filename );
     229            $type = wp_check_filetype( $filename )['type'];
     230
     231            // phpcs:ignore WordPress.WP.AlternativeFunctions
     232            $content = file_get_contents( $filename );
     233
     234            if ( false === $content ) {
     235                return new WP_Error( 'sending', esc_html__( 'Cannot read poster file' ) );
     236            }
     237
     238            $body[] = "--$boundary";
     239            $body[] = "Content-Disposition: form-data; name=\"$name\"; filename=\"$file\"";
     240            $body[] = "Content-Type: $type";
     241            $body[] = "\r\n" . $content;
     242        }
     243
     244        // Add final boundary.
     245        $body[] = "--$boundary--\r\n";
     246
     247        return implode( "\r\n", $body );
     248    }
     249
     250    /**
     251     * Prepare message excerpt.
     252     *
     253     * @param array $message List of message args.
     254     */
     255    private static function prepare_message_excerpt( $message ) {
     256        $excerpt = array();
     257
     258        if ( ! empty( $message['excerpt'] ) ) {
     259            $message['excerpt'] = preg_replace( '/\*(.+?)\*/s', '<b>$1</b>', $message['excerpt'] );
     260            $message['excerpt'] = preg_replace( '/_(.+?)_/s', '<i>$1</i>', $message['excerpt'] );
     261
     262            $excerpt[] = $message['excerpt'];
     263        }
     264
     265        if ( ! empty( $message['link'] ) ) {
     266            $excerpt[] = $message['link'];
     267        }
     268
     269        $excerpt = implode( "\n\n", $excerpt );
     270
     271        /**
     272         * Filter message excerpt right before sending.
     273         *
     274         * @param string $excerpt Message excerpt.
     275         * @param array  $message Original message array.
     276         * @param string $network Network name.
     277         */
     278        return apply_filters( 'social_planner_prepare_excerpt', $excerpt, $message, self::NETWORK_NAME );
    198279    }
    199280
     
    216297        }
    217298
     299        /**
     300         * Filter request arguments right before sending.
     301         *
     302         * @param string $args    Request arguments.
     303         * @param array  $url     URL to retrieve.
     304         * @param string $network Network name.
     305         *
     306         * @since 1.1.12
     307         */
     308        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     309
    218310        return wp_remote_post( $url, $args );
    219311    }
    220 
    221     /**
    222      * Create multipart data.
    223      *
    224      * @param array  $data     List of default query params.
    225      * @param array  $files    List of files.
    226      * @param string $boundary Boundary delimiter.
    227      */
    228     private static function prepare_multipart_data( $data, $files, $boundary ) {
    229         $body = array();
    230 
    231         foreach ( $data as $key => $value ) {
    232             $body[] = "--$boundary";
    233             $body[] = "Content-Disposition: form-data; name=\"$key\"";
    234             $body[] = "\r\n" . $value;
    235         }
    236 
    237         foreach ( $files as $name => $filename ) {
    238             $file = basename( $filename );
    239             $type = wp_check_filetype( $filename )['type'];
    240 
    241             // phpcs:ignore WordPress.WP.AlternativeFunctions
    242             $content = file_get_contents( $filename );
    243 
    244             if ( false === $content ) {
    245                 return new WP_Error( 'sending', esc_html__( 'Cannot read poster file' ) );
    246             }
    247 
    248             $body[] = "--$boundary";
    249             $body[] = "Content-Disposition: form-data; name=\"$name\"; filename=\"$file\"";
    250             $body[] = "Content-Type: $type";
    251             $body[] = "\r\n" . $content;
    252         }
    253 
    254         // Add final boundary.
    255         $body[] = "--$boundary--\r\n";
    256 
    257         return implode( "\r\n", $body );
    258     }
    259 
    260     /**
    261      * Prepare message excerpt.
    262      *
    263      * @param array $message List of message args.
    264      */
    265     private static function prepare_message_excerpt( $message ) {
    266         $excerpt = array();
    267 
    268         if ( ! empty( $message['excerpt'] ) ) {
    269             $message['excerpt'] = preg_replace( '/\*(.+?)\*/s', '<b>$1</b>', $message['excerpt'] );
    270             $message['excerpt'] = preg_replace( '/_(.+?)_/s', '<i>$1</i>', $message['excerpt'] );
    271 
    272             $excerpt[] = $message['excerpt'];
    273         }
    274 
    275         if ( ! empty( $message['link'] ) ) {
    276             $excerpt[] = $message['link'];
    277         }
    278 
    279         $excerpt = implode( "\n\n", $excerpt );
    280 
    281         /**
    282          * Filter message excerpt right before sending.
    283          *
    284          * @param string $excerpt Message excerpt.
    285          * @param array  $message Original message array.
    286          * @param string $network Network name.
    287          */
    288         return apply_filters( 'social_planner_prepare_excerpt', $excerpt, $message, self::NETWORK_NAME );
    289     }
    290312}
  • social-planner/trunk/networks/class-network-twitter.php

    r2699801 r2903429  
    181181        );
    182182
     183        /**
     184         * Filter request body arguments using message data.
     185         *
     186         * @param string $body    Request body arguments.
     187         * @param array  $message Message data.
     188         * @param string $network Network name.
     189         *
     190         * @since 1.1.12
     191         */
     192        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
     193
    183194        return self::send_request( $url, $body, $headers );
    184195    }
     
    233244
    234245    /**
     246     * Create multipart data.
     247     *
     248     * @param string $path     Path to local file.
     249     * @param string $name     Name of body parameter.
     250     * @param string $boundary Boundary delimiter.
     251     */
     252    private static function prepare_multipart_data( $path, $name, $boundary ) {
     253        $file = basename( $path );
     254        $type = wp_check_filetype( $path )['type'];
     255
     256        // phpcs:ignore WordPress.WP.AlternativeFunctions
     257        $content = file_get_contents( $path );
     258
     259        if ( false === $content ) {
     260            return new WP_Error( 'sending', esc_html__( 'Cannot read poster file', 'social-planner' ) );
     261        }
     262
     263        $body[] = "--$boundary";
     264        $body[] = "Content-Disposition: form-data; name=\"$name\"; filename=\"$file\"";
     265        $body[] = "Content-Type: $type";
     266        $body[] = "\r\n" . $content;
     267        $body[] = "--$boundary--\r\n";
     268
     269        return implode( "\r\n", $body );
     270    }
     271
     272    /**
     273     * Create status from message object.
     274     *
     275     * @param array $message List of message args.
     276     */
     277    private static function prepare_message_excerpt( $message ) {
     278        $excerpt = array();
     279
     280        if ( ! empty( $message['excerpt'] ) ) {
     281            $excerpt[] = $message['excerpt'];
     282        }
     283
     284        if ( ! empty( $message['link'] ) ) {
     285            $excerpt[] = $message['link'];
     286        }
     287
     288        $excerpt = implode( "\n\n", $excerpt );
     289
     290        /**
     291         * Filter message excerpt right before sending.
     292         *
     293         * @param string $excerpt Message excerpt.
     294         * @param array  $message Original message array.
     295         * @param string $network Network name.
     296         */
     297        return apply_filters( 'social_planner_prepare_excerpt', $excerpt, $message, self::NETWORK_NAME );
     298    }
     299
     300    /**
     301     * Generate OAuth signature.
     302     *
     303     * @param string $url API endpoint.
     304     * @param string $secret Generated secret.
     305     * @param array  $fields List of query arguments.
     306     */
     307    private static function get_oauth_signature( $url, $secret, $fields ) {
     308        ksort( $fields );
     309
     310        $values = array();
     311
     312        foreach ( $fields as $key => $value ) {
     313            $values[] = "$key=" . rawurlencode( $value );
     314        }
     315
     316        $base = 'POST&' . rawurlencode( $url ) . '&' . rawurlencode( implode( '&', $values ) );
     317
     318        // phpcs:ignore
     319        return base64_encode( hash_hmac( 'sha1', $base, $secret, true ) );
     320    }
     321
     322    /**
     323     * Build OAuth header.
     324     *
     325     * @param array $fields List of header arguments.
     326     */
     327    private static function build_oauth_header( $fields ) {
     328        $values = array();
     329
     330        foreach ( $fields as $key => $value ) {
     331            $values[] = $key . '="' . rawurlencode( $value ) . '"';
     332        }
     333
     334        return 'OAuth ' . implode( ', ', $values );
     335    }
     336
     337    /**
    235338     * Send request to remote server.
    236339     *
     
    250353        }
    251354
     355        /**
     356         * Filter request arguments right before sending.
     357         *
     358         * @param string $args    Request arguments.
     359         * @param array  $url     URL to retrieve.
     360         * @param string $network Network name.
     361         *
     362         * @since 1.1.12
     363         */
     364        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     365
    252366        return wp_remote_post( $url, $args );
    253367    }
    254 
    255     /**
    256      * Create multipart data.
    257      *
    258      * @param string $path     Path to local file.
    259      * @param string $name     Name of body parameter.
    260      * @param string $boundary Boundary delimiter.
    261      */
    262     private static function prepare_multipart_data( $path, $name, $boundary ) {
    263         $file = basename( $path );
    264         $type = wp_check_filetype( $path )['type'];
    265 
    266         // phpcs:ignore WordPress.WP.AlternativeFunctions
    267         $content = file_get_contents( $path );
    268 
    269         if ( false === $content ) {
    270             return new WP_Error( 'sending', esc_html__( 'Cannot read poster file', 'social-planner' ) );
    271         }
    272 
    273         $body[] = "--$boundary";
    274         $body[] = "Content-Disposition: form-data; name=\"$name\"; filename=\"$file\"";
    275         $body[] = "Content-Type: $type";
    276         $body[] = "\r\n" . $content;
    277         $body[] = "--$boundary--\r\n";
    278 
    279         return implode( "\r\n", $body );
    280     }
    281 
    282     /**
    283      * Create status from message object.
    284      *
    285      * @param array $message List of message args.
    286      */
    287     private static function prepare_message_excerpt( $message ) {
    288         $excerpt = array();
    289 
    290         if ( ! empty( $message['excerpt'] ) ) {
    291             $excerpt[] = $message['excerpt'];
    292         }
    293 
    294         if ( ! empty( $message['link'] ) ) {
    295             $excerpt[] = $message['link'];
    296         }
    297 
    298         $excerpt = implode( "\n\n", $excerpt );
    299 
    300         /**
    301          * Filter message excerpt right before sending.
    302          *
    303          * @param string $excerpt Message excerpt.
    304          * @param array  $message Original message array.
    305          * @param string $network Network name.
    306          */
    307         return apply_filters( 'social_planner_prepare_excerpt', $excerpt, $message, self::NETWORK_NAME );
    308     }
    309 
    310     /**
    311      * Generate OAuth signature.
    312      *
    313      * @param string $url API endpoint.
    314      * @param string $secret Generated secret.
    315      * @param array  $fields List of query arguments.
    316      */
    317     private static function get_oauth_signature( $url, $secret, $fields ) {
    318         ksort( $fields );
    319 
    320         $values = array();
    321 
    322         foreach ( $fields as $key => $value ) {
    323             $values[] = "$key=" . rawurlencode( $value );
    324         }
    325 
    326         $base = 'POST&' . rawurlencode( $url ) . '&' . rawurlencode( implode( '&', $values ) );
    327 
    328         // phpcs:ignore
    329         return base64_encode( hash_hmac( 'sha1', $base, $secret, true ) );
    330     }
    331 
    332     /**
    333      * Build OAuth header.
    334      *
    335      * @param array $fields List of header arguments.
    336      */
    337     private static function build_oauth_header( $fields ) {
    338         $values = array();
    339 
    340         foreach ( $fields as $key => $value ) {
    341             $values[] = $key . '="' . rawurlencode( $value ) . '"';
    342         }
    343 
    344         return 'OAuth ' . implode( ', ', $values );
    345     }
    346368}
  • social-planner/trunk/networks/class-network-vk.php

    r2699801 r2903429  
    159159        );
    160160
    161         $url = 'https://api.vk.com/method/wall.post';
     161        /**
     162         * Filter request body arguments using message data.
     163         *
     164         * @param string $body    Request body arguments.
     165         * @param array  $message Message data.
     166         * @param string $network Network name.
     167         *
     168         * @since 1.1.12
     169         */
     170        $body = apply_filters( 'social_planner_filter_request_body', $body, $message, self::NETWORK_NAME );
    162171
    163172        // Publish message.
    164         return self::send_request( $url, $body );
     173        return self::send_request( 'https://api.vk.com/method/wall.post', $body );
    165174    }
    166175
     
    192201        }
    193202
    194         $url = 'https://api.vk.com/method/photos.saveWallPhoto';
    195 
    196203        // Save image to VK.com wall.
    197         $response = self::send_request( $url, array_merge( $body, $options ) );
     204        $response = self::send_request( 'https://api.vk.com/method/photos.saveWallPhoto', array_merge( $body, $options ) );
    198205
    199206        if ( is_wp_error( $response ) ) {
     
    262269     */
    263270    private static function get_upload_server( $body ) {
    264         $url = 'https://api.vk.com/method/photos.getWallUploadServer';
    265 
    266271        // Try to get VK wall upload server.
    267         $response = self::send_request( $url, $body );
     272        $response = self::send_request( 'https://api.vk.com/method/photos.getWallUploadServer', $body );
    268273
    269274        if ( is_wp_error( $response ) ) {
     
    369374        }
    370375
     376        /**
     377         * Filter request arguments right before sending.
     378         *
     379         * @param string $args    Request arguments.
     380         * @param array  $url     URL to retrieve.
     381         * @param string $network Network name.
     382         *
     383         * @since 1.1.12
     384         */
     385        $args = apply_filters( 'social_planner_before_request', $args, $url, self::NETWORK_NAME );
     386
    371387        return wp_remote_post( $url, $args );
    372388    }
  • social-planner/trunk/readme.txt

    r2839003 r2903429  
    44Tags: automation, autopost, auto-post, auto post, socialnetworks, socialnetwork, social networks, social network, facebook, twitter, telegram, vkontakte, vk.com, ok.ru, api, social images, social image, sharing, share, repost, re-post, open graph
    55Requires at least: 5.3
    6 Tested up to: 6.1
    7 Stable tag: 1.1.11
     6Tested up to: 6.2
     7Stable tag: 1.1.12
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    5151== Changelog ==
    5252
     53= 1.1.12 =
     54* Adding `social_planner_before_request` and `social_planner_filter_request_body` filters for each network class
     55
    5356= 1.1.11 =
    5457* Fixing `subscribeOnSaving` error on Post editor while using Classic Editor
  • social-planner/trunk/social-planner.php

    r2839003 r2903429  
    88 * Requires at least: 5.3
    99 * Tested up to: 5.8
    10  * Version: 1.1.11
     10 * Version: 1.1.12
    1111 *
    1212 * Text Domain: social-planner
     
    2929 * Plugin version.
    3030 */
    31 define( 'SOCIAL_PLANNER_VERSION', '1.1.11' );
     31define( 'SOCIAL_PLANNER_VERSION', '1.1.12' );
    3232
    3333/**
     
    4444 * Shortcut constant to the path of this file.
    4545 */
    46 define( 'SOCIAL_PLANNER_DIR', dirname( __FILE__ ) );
     46define( 'SOCIAL_PLANNER_DIR', __DIR__ );
    4747
    4848/**
Note: See TracChangeset for help on using the changeset viewer.