Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
1.44% covered (danger)
1.44%
3 / 208
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Publicize_UI
1.44% covered (danger)
1.44%
3 / 208
0.00% covered (danger)
0.00%
0 / 7
1207.76
0.00% covered (danger)
0.00%
0 / 1
 __construct
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 init
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 sharing_menu
n/a
0 / 0
n/a
0 / 0
1
 wrapper_admin_page
n/a
0 / 0
n/a
0 / 0
2
 management_page
n/a
0 / 0
n/a
0 / 0
1
 load_assets
n/a
0 / 0
n/a
0 / 0
2
 admin_page
n/a
0 / 0
n/a
0 / 0
1
 post_page_metabox_assets
0.00% covered (danger)
0.00%
0 / 56
0.00% covered (danger)
0.00%
0 / 1
42
 connection_label
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 post_page_metabox
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
42
 get_metabox_form_connected
0.00% covered (danger)
0.00%
0 / 55
0.00% covered (danger)
0.00%
0 / 1
90
 get_message_placeholders
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Publicize_UI class.
4 *
5 * @package automattic/jetpack-publicize
6 */
7
8namespace Automattic\Jetpack\Publicize;
9
10use Automattic\Jetpack\Assets;
11use Automattic\Jetpack\Current_Plan;
12use Automattic\Jetpack\Publicize\Publicize_Utils as Utils;
13use Automattic\Jetpack\Status\Host;
14
15/**
16 * Only user facing pieces of Publicize are found here.
17 */
18class Publicize_UI {
19    /**
20     * Contains an instance of class 'Publicize' which loads Keyring, sets up services, etc.
21     *
22     * @var Publicize Instance of Publicize
23     */
24    public $publicize;
25
26    /**
27     * URL to Sharing settings page in wordpress.com
28     *
29     * @var string
30     */
31    protected $publicize_settings_url = '';
32
33    /**
34     * Hooks into WordPress to display the various pieces of UI and load our assets
35     */
36    public function __construct() {
37        global $publicize;
38        if ( ! is_object( $publicize ) ) {
39            $publicize = new Publicize();
40        }
41        $this->publicize = $publicize;
42
43        add_action( 'admin_init', array( $this, 'init' ) );
44    }
45
46    /**
47     * Initialize UI-related functionality.
48     */
49    public function init() {
50        // Show only to users with the capability required to manage their Publicize connections.
51        if ( ! Utils::is_publicize_active() || ! $this->publicize->current_user_can_access_publicize_data() ) {
52            return;
53        }
54
55        $this->publicize_settings_url = $this->publicize->publicize_connections_url();
56
57        // Assets (css, js).
58        add_action( 'admin_head-post.php', array( $this, 'post_page_metabox_assets' ) );
59        add_action( 'admin_head-post-new.php', array( $this, 'post_page_metabox_assets' ) );
60
61        // Management of publicize (sharing screen, ajax/lightbox popup, and metabox on post screen).
62        add_action( 'post_submitbox_misc_actions', array( $this, 'post_page_metabox' ) );
63    }
64
65    /**
66     * If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still
67     *
68     * @deprecated 0.42.3
69     */
70    public function sharing_menu() {
71        add_submenu_page(
72            'options-general.php',
73            esc_html__( 'Sharing Settings', 'jetpack-publicize-pkg' ),
74            esc_html__( 'Sharing', 'jetpack-publicize-pkg' ),
75            'publish_posts',
76            'sharing',
77            array( $this, 'wrapper_admin_page' )
78        );
79    }
80
81    /**
82     * Add admin page with wrapper.
83     *
84     * @deprecated 0.42.3
85     */
86    public function wrapper_admin_page() {
87        if ( class_exists( 'Jetpack_Admin_Page' ) ) {
88            \Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ) );
89        }
90    }
91
92    /**
93     * Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists.
94     *
95     * @deprecated 0.42.3
96     */
97    public function management_page() {
98        ?>
99        <div class="wrap">
100            <div class="icon32" id="icon-options-general"><br /></div>
101            <h1><?php esc_html_e( 'Sharing Settings', 'jetpack-publicize-pkg' ); ?></h1>
102
103            <?php
104            /** This action is documented in modules/sharedaddy/sharing.php */
105            do_action( 'pre_admin_screen_sharing' );
106            ?>
107        </div>
108        <?php
109    }
110
111    /**
112     * Styling for the sharing screen and popups
113     * JS for the options and switching
114     *
115     * @deprecated 0.42.3
116     */
117    public function load_assets() {
118        if ( class_exists( 'Jetpack_Admin_Page' ) ) {
119            \Jetpack_Admin_Page::load_wrapper_styles();
120        }
121    }
122
123    /**
124     * Lists the current user's publicized accounts for the blog
125     * looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring
126     *
127     * @deprecated 0.42.3
128     */
129    public function admin_page() {
130        ?>
131        <h2 id="publicize"><?php esc_html_e( 'Jetpack Social', 'jetpack-publicize-pkg' ); ?></h2>
132        <p><?php esc_html_e( 'Connect social media services to automatically share new posts.', 'jetpack-publicize-pkg' ); ?></p>
133        <h4>
134            <?php
135            printf(
136                wp_kses(
137                    /* translators: %s is the link to the Publicize page in Calypso */
138                    __( "We've made some updates to Jetpack Social. Please visit the <a href='%s' class='jptracks' data-jptracks-name='legacy_publicize_settings'>WordPress.com sharing page</a> to manage your Jetpack Social connections or use the button below.", 'jetpack-publicize-pkg' ),
139                    array(
140                        'a' => array(
141                            'href'               => array(),
142                            'class'              => array(),
143                            'data-jptracks-name' => array(),
144                        ),
145                    )
146                ),
147                esc_url( $this->publicize->publicize_connections_url() )
148            );
149            ?>
150        </h4>
151
152        <a href="<?php echo esc_url( $this->publicize->publicize_connections_url() ); ?>" class="button button-primary jptracks" data-jptracks-name='legacy_publicize_settings'><?php esc_html_e( 'Jetpack Social Settings', 'jetpack-publicize-pkg' ); ?></a>
153        <?php
154    }
155
156    /**
157     * CSS for styling the publicize message box and counter that displays on the post page.
158     * There is also some JavaScript for length counting and some basic display effects.
159     */
160    public function post_page_metabox_assets() {
161        // We don't need those assets for the block editor pages.
162        $current_screen = get_current_screen();
163        if ( $current_screen && $current_screen->is_block_editor ) {
164            return;
165        }
166
167        $is_atomic_site = ( new Host() )->is_woa_site();
168        $is_simple_site = ( new Host() )->is_wpcom_simple();
169        $site_type      = $is_atomic_site ? 'atomic' : ( $is_simple_site ? 'simple' : 'jetpack' );
170
171        Assets::register_script(
172            'jetpack-social-classic-editor-options',
173            '../build/classic-editor.js',
174            __FILE__,
175            array(
176                'in_footer'  => true,
177                'enqueue'    => true,
178                'textdomain' => 'jetpack-publicize-pkg',
179            )
180        );
181
182        wp_add_inline_script(
183            'jetpack-social-classic-editor-options',
184            'var jetpackSocialClassicEditorOptions = ' . wp_json_encode(
185                array(
186                    'connectionsUrl'              => esc_url( $this->publicize_settings_url ),
187                    'isEnhancedPublishingEnabled' => $this->publicize->has_enhanced_publishing_feature(),
188                    'resharePath'                 => '/wpcom/v2/publicize/share-post/{postId}',
189                    'refreshConnections'          => '/wpcom/v2/publicize/connections?test_connections=1',
190                    'isReshareSupported'          => Current_Plan::supports( 'republicize' ),
191                    'siteType'                    => $site_type,
192                ),
193                JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP
194            ),
195            'before'
196        );
197
198        $default_prefix = $this->publicize->default_prefix;
199        $default_prefix = preg_replace( '/%([0-9])\$s/', '" + %\\1$s + "', wp_json_encode( (string) $default_prefix, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) );
200
201        $default_message = $this->publicize->default_message;
202        $default_message = preg_replace( '/%([0-9])\$s/', '" + %\\1$s + "', wp_json_encode( (string) $default_message, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) );
203
204        $default_suffix = $this->publicize->default_suffix;
205        $default_suffix = preg_replace( '/%([0-9])\$s/', '" + %\\1$s + "', wp_json_encode( (string) $default_suffix, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) );
206
207        $max_length = defined( 'JETPACK_PUBLICIZE_TWITTER_LENGTH' ) ? JETPACK_PUBLICIZE_TWITTER_LENGTH : 280;
208        $max_length = $max_length - 24; // t.co link, space.
209
210        ?>
211
212<script type="text/javascript">
213jQuery( function($) {
214    var wpasTitleCounter    = $( '#wpas-title-counter' ),
215        wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).length,
216        postTitle = $( '#title' ),
217        wpasTitle = $( '#wpas-title' ).keyup( function() {
218            var postTitleVal,
219                length = wpasTitle.val().length;
220
221            if ( ! length ) {
222                length = wpasTitle.attr( 'placeholder' ).length;
223            }
224
225            wpasTitleCounter.text( length ).trigger( 'change' );
226        } ),
227        authClick = false;
228
229    wpasTitleCounter.on( 'change', function( e ) {
230        if ( wpasTwitterCheckbox && parseInt( $( e.currentTarget ).text(), 10 ) > <?php echo (int) $max_length; ?> ) {
231            wpasTitleCounter.addClass( 'wpas-twitter-length-limit' );
232        } else {
233            wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' );
234        }
235    } );
236
237    // Keep the postTitle and the placeholder in sync
238    postTitle.on( 'keyup', function( e ) {
239        var url = $( '#sample-permalink' ).text();
240        <?php // phpcs:ignore ?>
241        var defaultMessage = $.trim( <?php printf( $default_prefix, 'url' ); ?> + <?php printf( $default_message, 'e.currentTarget.value', 'url' ); ?> + <?php printf( $default_suffix, 'url' ); ?> )
242            .replace( /<[^>]+>/g,'');
243
244        wpasTitle.attr( 'placeholder', defaultMessage );
245        wpasTitle.trigger( 'keyup' );
246    } );
247
248    // set the initial placeholder
249    postTitle.trigger( 'keyup' );
250
251    // If a custom message has been provided, open the UI so the author remembers
252    if ( wpasTitle.val() && ! wpasTitle.prop( 'disabled' ) && wpasTitle.attr( 'placeholder' ) !== wpasTitle.val() ) {
253        $( '#publicize-form' ).show();
254        $( '#publicize-defaults' ).hide();
255        $( '#publicize-form-edit' ).hide();
256    }
257
258    $('#publicize-disconnected-form-show').click( function() {
259        $('#publicize-form').slideDown( 'fast' );
260        $(this).hide();
261    } );
262
263    $('#publicize-disconnected-form-hide').click( function() {
264        $('#publicize-form').slideUp( 'fast' );
265        $('#publicize-disconnected-form-show').show();
266    } );
267
268    $('#publicize-form-edit').click( function() {
269        $('#publicize-form').slideDown( 'fast', function() {
270            var selBeg = 0, selEnd = 0;
271            wpasTitle.focus();
272
273            if ( ! wpasTitle.text() ) {
274                wpasTitle.text( wpasTitle.attr( 'placeholder' ) );
275
276                selBeg = wpasTitle.text().indexOf( postTitle.val() );
277                if ( selBeg < 0 ) {
278                    selBeg = 0;
279                } else {
280                    selEnd = selBeg + postTitle.val().length;
281                }
282
283                var domObj = wpasTitle.get(0);
284                if ( domObj.setSelectionRange ) {
285                    domObj.setSelectionRange( selBeg, selEnd );
286                } else if ( domObj.createTextRange ) {
287                    var r = domObj.createTextRange();
288                    r.moveStart( 'character', selBeg );
289                    r.moveEnd( 'character', selEnd );
290                    r.select();
291                }
292            }
293        } );
294
295        $('#publicize-defaults').hide();
296        $(this).hide();
297        return false;
298    } );
299
300
301    $('#publicize-form-hide').click( function() {
302        var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) {
303            return $.trim( $(el).parent( 'label' ).text() );
304        } );
305        $('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show();
306        $('#publicize-form-edit').show();
307        return false;
308    } );
309
310    $('.authorize-link').click( function() {
311        if ( authClick ) {
312            return false;
313        }
314        authClick = true;
315        $(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' );
316        $.ajaxSetup( { async: false } );
317
318        if ( window.wp && window.wp.autosave ) {
319            window.wp.autosave.server.triggerSave();
320        } else {
321            autosave();
322        }
323
324        return true;
325    } );
326
327    $( '.pub-service' ).click( function() {
328        var service = $(this).data( 'service' ),
329            fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />';
330        $( '#add-publicize-check' ).append( fakebox );
331    } );
332
333    // X Developer Policy forbids posting the same content to more than one
334    // X account. Only one X checkbox may be checked at a time; turning one
335    // on unchecks the others.
336    $( document ).on( 'change', '.wpas-submit-x', function() {
337        if ( ! this.checked ) {
338            return;
339        }
340        $( '.wpas-submit-x' ).not( this ).prop( 'checked', false );
341    } );
342} );
343</script>
344
345<style type="text/css">
346#publicize {
347    line-height: 1.5;
348}
349#publicize ul {
350    margin: 4px 0 4px 6px;
351}
352#publicize li {
353    margin: 0;
354}
355#publicize textarea {
356    margin: 4px 0 0;
357    width: 100%
358}
359#publicize ul.not-connected {
360    list-style: square;
361    padding-left: 1em;
362}
363.wpas-disabled {
364    color: #999;
365}
366.publicize__notice-warning {
367    display: block;
368    padding: 7px 10px;
369    margin: 5px 0;
370    border-left-width: 4px;
371    border-left-style: solid;
372    font-size: 12px;
373    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
374}
375.publicize__notice-media-warning {
376    border-right: 1px solid #c3c4c7;
377    border-bottom: 1px solid #c3c4c7;
378    border-top: 1px solid #c3c4c7;
379}
380.publicize-external-link {
381    display: block;
382    text-decoration: none;
383    margin-top: 8px;
384}
385.publicize-external-link__text {
386    text-decoration: underline;
387}
388#publicize-title::before {
389    content: "\f237";
390    font: normal 20px/1 dashicons;
391    speak: none;
392    margin-left: -1px;
393    padding-right: 3px;
394    vertical-align: top;
395    -webkit-font-smoothing: antialiased;
396    color: #8c8f94;
397}
398.post-new-php .authorize-link, .post-php .authorize-link {
399    line-height: 1.5em;
400}
401.post-new-php .authorize-message, .post-php .authorize-message {
402    margin-bottom: 0;
403}
404#poststuff #publicize .updated p {
405    margin: .5em 0;
406}
407.wpas-twitter-length-limit {
408    color: red;
409}
410.publicize__notice-warning .dashicons {
411    font-size: 16px;
412    text-decoration: none;
413}
414.publicize-placeholders-help {
415    margin: 0.5rem 0 1rem;
416}
417</style>
418        <?php
419    }
420
421    /**
422     * Get the connection label.
423     *
424     * @param string $service_label Service's human-readable Label ("Facebook", "Twitter", ...).
425     * @param string $display_name Connection's human-readable Username ("@jetpack", ...).
426     * @return string
427     */
428    private function connection_label( $service_label, $display_name ) {
429        return sprintf(
430            /* translators: %1$s: Service Name (Facebook, Twitter, ...), %2$s: Username on Service (@jetpack, ...) */
431            __( '%1$s: %2$s', 'jetpack-publicize-pkg' ),
432            $service_label,
433            $display_name
434        );
435    }
436
437    /**
438     * Controls the metabox that is displayed on the post page
439     * Allows the user to customize the message that will be sent out to the social network, as well as pick which
440     * networks to publish to. Also displays the character counter and some other information.
441     */
442    public function post_page_metabox() {
443        global $post;
444
445        if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) ) {
446            return;
447        }
448
449        $connections_data = $this->publicize->get_filtered_connection_data();
450
451        if ( ! is_array( $connections_data ) ) {
452            $connections_data = array();
453        }
454        ?>
455        <div id="publicize" class="misc-pub-section misc-pub-section-last">
456            <span id="publicize-title">
457            <?php
458            esc_html_e( 'Jetpack Social:', 'jetpack-publicize-pkg' );
459
460            if ( ! empty( $connections_data ) ) :
461                $publicize_form = $this->get_metabox_form_connected( $connections_data );
462
463                $labels = array();
464
465                foreach ( $connections_data as $connection_data ) {
466                    if ( ! $connection_data['enabled'] ) {
467                        continue;
468                    }
469
470                    $labels[] = sprintf(
471                        '<strong>%s</strong>',
472                        esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) )
473                    );
474                }
475
476                ?>
477                    <?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- labels are already escaped above ?>
478                    <span id="publicize-defaults"><?php echo implode( ', ', $labels ); ?></span>
479                    <a href="#" id="publicize-form-edit"><?php esc_html_e( 'Edit', 'jetpack-publicize-pkg' ); ?></a>&nbsp;<a href="<?php echo esc_url( $this->publicize->publicize_connections_url() ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'Settings', 'jetpack-publicize-pkg' ); ?></a><br />
480                    <?php
481            else :
482                $publicize_form = '';
483                ?>
484                <strong><?php esc_html_e( 'Not Connected', 'jetpack-publicize-pkg' ); ?></strong>
485                <a href="<?php echo esc_url( $this->publicize->publicize_connections_url() ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'Settings', 'jetpack-publicize-pkg' ); ?></a><br />
486                <?php
487
488            endif;
489            ?>
490            </span>
491            <?php
492            /**
493             * Fires right before rendering the Publicize form in the Classic
494             * Editor.
495             *
496             * @since 0.14.0
497             */
498            do_action( 'publicize_classic_editor_form_before' );
499
500            /**
501             * Filter the Publicize details form.
502             *
503             * @since 0.1.0
504             * @since-jetpack 2.0.0
505             *
506             * @param string $publicize_form Publicize Details form appearing above Publish button in the editor.
507             */
508            echo apply_filters( 'publicize_form', $publicize_form ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Parts of the form are escaped individually in the code above.
509
510            /**
511             * Fires right after rendering the Publicize form in the Classic
512             * Editor.
513             *
514             * @since 0.14.0
515             */
516            do_action( 'publicize_classic_editor_form_after' );
517            ?>
518        </div>
519        <?php
520    }
521
522    /**
523     * Generates HTML content for connections form.
524     *
525     * @since 0.1.0
526     * @since-jetpack 6.7.0
527     *
528     * @global WP_Post $post The current post instance being published.
529     *
530     * @param array $connections_data Array of connections.
531     * @return array {
532     *     Array of content for generating connection form.
533     *
534     *     @type string HTML content of form
535     *     @type array {
536     *          Array of connection labels for active connections only.
537     *
538     *          @type string Connection label string.
539     *     }
540     * }
541     */
542    private function get_metabox_form_connected( $connections_data ) {
543        global $post;
544
545        ob_start();
546
547        ?>
548        <div id="publicize-form" class="hide-if-js">
549            <ul>
550        <?php
551
552        foreach ( $connections_data as $connection_data ) {
553            ?>
554
555            <li>
556                <label
557                    for="wpas-submit-<?php echo esc_attr( $connection_data['connection_id'] ); ?>"
558                >
559                    <input
560                        type="checkbox"
561                        name="wpas[submit][<?php echo esc_attr( $connection_data['connection_id'] ); ?>]"
562                        id="wpas-submit-<?php echo esc_attr( $connection_data['connection_id'] ); ?>"
563                        class="wpas-submit-<?php echo esc_attr( $connection_data['service_name'] ); ?>"
564                        value="1"
565                        data-id="<?php echo esc_attr( $connection_data['connection_id'] ); ?>"
566                    <?php
567                        checked( true, $connection_data['enabled'] );
568                    ?>
569                    />
570                    <?php echo esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) ); ?>
571
572                </label>
573            </li>
574            <?php
575        }
576
577        $title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true );
578        if ( ! $title ) {
579            $title = '';
580        }
581
582        $is_social_note = 'jetpack-social-note' === get_post_type( $post->ID );
583
584        $is_post_published = 'publish' === get_post_status( $post->ID );
585
586        $templates_enabled = Current_Plan::supports( 'social-message-templates' );
587
588        $placeholders = $this->get_message_placeholders();
589
590        ?>
591
592            </ul>
593
594            <?php if ( ! $is_social_note ) : ?>
595                <label for="wpas-title"><?php esc_html_e( 'Custom Message:', 'jetpack-publicize-pkg' ); ?></label>
596                <?php if ( ! $templates_enabled ) : ?>
597                    <span id="wpas-title-counter" class="alignright hide-if-no-js">0</span>
598                <?php endif; ?>
599                <textarea name="wpas_title" id="wpas-title"><?php echo esc_textarea( $title ); ?></textarea>
600                <?php if ( $templates_enabled ) : ?>
601                    <details class="publicize-placeholders-help">
602                        <summary><?php esc_html_e( 'Available placeholders', 'jetpack-publicize-pkg' ); ?></summary>
603                        <p>
604                            <?php esc_html_e( 'Use placeholders to automatically insert post details.', 'jetpack-publicize-pkg' ); ?>
605                        </p>
606                        <ul>
607                            <?php foreach ( $placeholders as $placeholder ) : ?>
608                                <li>
609                                    <code><?php echo esc_html( $placeholder['token'] ); ?></code>
610                                    &mdash; <?php echo esc_html( $placeholder['description'] ); ?>
611                                </li>
612                            <?php endforeach; ?>
613                        </ul>
614                    </details>
615                <?php endif; ?>
616                <a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack-publicize-pkg' ); ?></a>
617                <input type="hidden" name="wpas[0]" value="1" />
618            <?php endif; ?>
619            <?php if ( $is_post_published && Current_Plan::supports( 'republicize' ) ) : ?>
620                <button type="button" class="hide-if-no-js button" id="publicize-share-now">
621                    <?php esc_html_e( 'Share now', 'jetpack-publicize-pkg' ); ?>
622                </button>
623                <span id="publicize-share-now-notice" class="hidden"></span>
624            <?php endif; ?>
625        </div>
626
627        <div id="pub-connection-needs-media"></div>
628        <div id="pub-connection-tests"></div>
629        <?php
630
631        return ob_get_clean();
632    }
633
634    /**
635     * Get the list of placeholders supported in custom Publicize messages.
636     *
637     * TODO: SOCIAL-471 — replace this hardcoded list with a fetch from WPCOM.
638     *
639     * @return array<int, array{token: string, description: string}>
640     */
641    private function get_message_placeholders() {
642        return array(
643            array(
644                'token'       => '{title}',
645                'description' => __( 'Post title', 'jetpack-publicize-pkg' ),
646            ),
647            array(
648                'token'       => '{excerpt}',
649                'description' => __( 'Post excerpt', 'jetpack-publicize-pkg' ),
650            ),
651            array(
652                'token'       => '{content}',
653                'description' => __( 'Full post content', 'jetpack-publicize-pkg' ),
654            ),
655            array(
656                'token'       => '{url}',
657                'description' => __( 'Permalink to the post', 'jetpack-publicize-pkg' ),
658            ),
659            array(
660                'token'       => '{short_url}',
661                'description' => __( 'Short URL of the post', 'jetpack-publicize-pkg' ),
662            ),
663            array(
664                'token'       => '{tags}',
665                'description' => __( 'Post tags as hashtags', 'jetpack-publicize-pkg' ),
666            ),
667            array(
668                'token'       => '{categories}',
669                'description' => __( 'Post categories', 'jetpack-publicize-pkg' ),
670            ),
671            array(
672                'token'       => '{author}',
673                'description' => __( 'Author display name', 'jetpack-publicize-pkg' ),
674            ),
675            array(
676                'token'       => '{date}',
677                'description' => __( 'Publication date', 'jetpack-publicize-pkg' ),
678            ),
679            array(
680                'token'       => '{site_name}',
681                'description' => __( 'Site title', 'jetpack-publicize-pkg' ),
682            ),
683            array(
684                'token'       => '{site_url}',
685                'description' => __( 'Site URL', 'jetpack-publicize-pkg' ),
686            ),
687            array(
688                'token'       => '{meta:<key>}',
689                'description' => __( 'Custom field value', 'jetpack-publicize-pkg' ),
690            ),
691        );
692    }
693}