Ejemplo n.º 1
0
 /**
  * Proactively resolve FQDN asynchronously before later use
  *
  * @since 1.3.0
  *
  * @link https://dev.chromium.org/developers/design-documents/dns-prefetching Chromium prefetch behavior
  * @link https://developer.mozilla.org/en-US/docs/Controlling_DNS_prefetching Firefox prefetch behavior
  *
  * @return void
  */
 public static function dnsPrefetch()
 {
     if (!(defined(get_called_class() . '::FQDN') && static::FQDN)) {
         return;
     }
     echo '<link rel="dns-prefetch" href="//' . esc_attr(static::FQDN) . '"' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>' . "\n";
 }
Ejemplo n.º 2
0
 /**
  * Build a HTML meta element from name and content values
  *
  * @since 1.0.0
  *
  * @param string $name    name attribute value
  * @param mixed  $content content attribute value. will be converted to string for output
  *
  * @return string HTML meta element or empty string if name and content attribute values not provided
  */
 public static function fromNameContentPair($name, $content)
 {
     if (!($name && $content)) {
         return '';
     }
     return '<meta name="' . esc_attr(self::PREFIX . $name) . '" content="' . esc_attr((string) $content) . '"' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>';
 }
Ejemplo n.º 3
0
 /**
  * Link to a site's Twitter profile using rel me
  *
  * Adds via attribution to Twitter widgets on the page
  *
  * @link http://microformats.org/wiki/rel-me XFN rel me
  *
  * @return void
  */
 public static function relMe()
 {
     $site_username = \Twitter\WordPress\Site\Username::getViaAttribution(in_the_loop() ? get_the_ID() : null);
     if ($site_username) {
         echo '<link rel="me" href="' . esc_url(\Twitter\Helpers\TwitterURL::profile($site_username), array('https', 'http')) . '"' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>';
     }
 }
Ejemplo n.º 4
0
 /**
  * Display Tweet Web Intent customizations
  *
  * @since 1.0.0
  *
  * @return void
  */
 public static function metaBoxContent()
 {
     $post = get_post();
     $stored_values = array();
     if ($post && is_a($post, 'WP_Post') && isset($post->ID)) {
         $stored_values = get_post_meta($post->ID, static::META_KEY, true);
         if (!is_array($stored_values)) {
             $stored_values = array();
         }
     }
     echo '<h4>' . esc_html(_x('Tweet', 'Tweet verb. Sharing.', 'twitter')) . '</h4>';
     echo '<table id="tweet-intent">';
     echo '<thead><tr><th scope="col">' . esc_html(_x('Parameter', 'Customization or variable', 'twitter')) . '</th><th scope="col">' . esc_html(_x('Value', 'Table column header: user-inputted value', 'twitter')) . '</th></tr></thead><tbody>';
     $available_characters = 140;
     // t.co wrapped URL length
     $short_url_length = static::getShortURLLength();
     if ($short_url_length) {
         // tweet length after accounting for the shared URL with a space separator
         $available_characters = $available_characters - $short_url_length - 1;
     }
     echo '<tr>';
     echo '<th scope="row" class="left"><label for="tweet-text">' . esc_html(_x('Text', 'Share / Tweet text', 'twitter')) . '</label></th>';
     echo '<td><input id="tweet-text" name="' . esc_attr(static::META_KEY . '[' . static::TEXT_KEY . ']') . '" type="text" maxlength="' . $available_characters . '" autocomplete="off"';
     if (isset($stored_values[static::TEXT_KEY])) {
         echo ' value="' . esc_attr($stored_values[static::TEXT_KEY]) . '"';
     } else {
         echo ' placeholder="' . esc_attr(get_the_title($post)) . '"';
     }
     echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '></td>';
     echo '</tr>';
     echo '<tr>';
     echo '<th scope="row" class="left"><label for="tweet-hashtags">' . esc_html(__('Hashtags', 'twitter')) . '</label></th>';
     echo '<td><input id="tweet-hashtags" name="' . esc_attr(static::META_KEY . '[' . static::HASHTAGS_KEY . ']') . '" type="text" maxlength="' . ($available_characters - 2) . '" autocomplete="off"';
     if (isset($stored_values[static::HASHTAGS_KEY]) && is_array($stored_values[static::HASHTAGS_KEY])) {
         echo ' value="' . esc_attr(implode(',', $stored_values[static::HASHTAGS_KEY])) . '"';
     }
     echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '></td>';
     echo '</tr>';
     echo '</tbody></table>';
     echo '<p class="description">' . esc_html(__('Pre-populate Tweet text', 'twitter')) . '</p>';
 }
Ejemplo n.º 5
0
 /**
  * Proactively resolve Twitter widget JS FQDN asynchronously before later use
  *
  * @since 1.0.0
  *
  * @link http://dev.chromium.org/developers/design-documents/dns-prefetching Chromium prefetch behavior
  * @link https://developer.mozilla.org/en-US/docs/Controlling_DNS_prefetching Firefox prefetch behavior
  *
  * @return void
  */
 public static function dnsPrefetch()
 {
     echo '<link rel="dns-prefetch" href="//' . esc_attr(self::FQDN) . '"';
     echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement();
     echo '>' . "\n";
 }
Ejemplo n.º 6
0
    /**
     * Settings update form
     *
     * @since 1.0.0
     *
     * @param array $instance Current settings
     *
     * @return void
     */
    public function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array_merge(array('title' => ''), \Twitter\WordPress\Shortcodes\Follow::$SHORTCODE_DEFAULTS));
        $close_void_element = \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement();
        ?>
		<p><label for="<?php 
        echo esc_attr($this->get_field_id('title'));
        ?>
"><?php 
        echo esc_html(__('Title:'));
        ?>
</label>
		<input class="widefat" id="<?php 
        echo esc_attr($this->get_field_id('title'));
        ?>
" name="<?php 
        echo esc_attr($this->get_field_name('title'));
        ?>
" type="text" value="<?php 
        echo esc_attr(trim(strip_tags($instance['title'])));
        ?>
"<?php 
        echo $close_void_element;
        ?>
></p>

		<p><label for="<?php 
        echo esc_attr($this->get_field_id('screen_name'));
        ?>
"><?php 
        echo esc_html(__('@username:'******'twitter'));
        ?>
</label>
		<input class="widefat" id="<?php 
        echo esc_attr($this->get_field_id('screen_name'));
        ?>
" name="<?php 
        echo esc_attr($this->get_field_name('screen_name'));
        ?>
" type="text" pattern="[a-zA-Z0-9_]{1,20}" value="<?php 
        echo esc_attr($instance['screen_name']);
        ?>
"<?php 
        echo $close_void_element;
        ?>
></p>

		<p><input class="checkbox" type="checkbox" id="<?php 
        echo esc_attr($this->get_field_id('show_screen_name'));
        ?>
" name="<?php 
        echo esc_attr($this->get_field_name('show_screen_name'));
        ?>
" value="1"<?php 
        checked($instance['show_screen_name']);
        echo $close_void_element;
        ?>
>
		<label for="<?php 
        echo esc_attr($this->get_field_id('show_screen_name'));
        ?>
"><?php 
        echo esc_html(__('Show username?', 'twitter'));
        ?>
</label></p>

		<p><input class="checkbox" type="checkbox" id="<?php 
        echo esc_attr($this->get_field_id('show_count'));
        ?>
" name="<?php 
        echo esc_attr($this->get_field_name('show_count'));
        ?>
" value="1"<?php 
        checked($instance['show_count']);
        echo $close_void_element;
        ?>
>
		<label for="<?php 
        echo esc_attr($this->get_field_id('show_count'));
        ?>
"><?php 
        echo esc_html(__('Show number of followers?', 'twitter'));
        ?>
</label></p>

		<p><label for="<?php 
        echo esc_attr($this->get_field_id('size'));
        ?>
"><?php 
        echo esc_html(__('Button size:', 'twitter'));
        ?>
</label>
		<fieldset id="<?php 
        echo esc_attr($this->get_field_id('size'));
        ?>
">
			<label><input type="radio" name="<?php 
        echo esc_attr($this->get_field_name('size'));
        ?>
" value="medium"<?php 
        checked('large' != $instance['size']);
        echo $close_void_element;
        ?>
> <?php 
        echo esc_html(_x('medium', 'medium size button', 'twitter'));
        ?>
 </label>
			<label><input type="radio" name="<?php 
        echo esc_attr($this->get_field_name('size'));
        ?>
" value="large"<?php 
        checked('large' == $instance['size']);
        echo $close_void_element;
        ?>
> <?php 
        echo esc_html(_x('large', 'large size button', 'twitter'));
        ?>
 </label>
		</fieldset></p>
<?php 
    }
Ejemplo n.º 7
0
 /**
  * Display Twitter Card customizations
  *
  * @since 1.0.0
  *
  * @return void
  */
 public static function metaBoxContent()
 {
     $post = get_post();
     $cards_fields_supported_by_post_type = array();
     $stored_values = array();
     if ($post && is_a($post, 'WP_Post') && isset($post->ID)) {
         $stored_values = get_post_meta($post->ID, static::META_KEY, true);
         if (!is_array($stored_values)) {
             $stored_values = array();
         }
         $cards_fields_supported_by_post_type = static::supportedCardFieldsByPostType(get_post_type($post));
     }
     // no supported Twitter Cards fields
     if (empty($cards_fields_supported_by_post_type)) {
         return;
     }
     // separate Twitter Cards content from Intent content above
     echo '<hr' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>';
     echo '<h4>' . esc_html(__('Twitter Card', 'twitter')) . '</h4>';
     if (isset($cards_fields_supported_by_post_type[static::TITLE_KEY])) {
         echo '<table id="twitter-card">';
         echo '<thead><tr><th scope="col">' . esc_html(_x('Property', 'Object component, such as a title and description of an article', 'twitter')) . '</th><th scope="col">' . esc_html(__('Value')) . '</th></tr></thead><tbody>';
         echo '<tr>';
         echo '<th scope="row" class="left"><label for="twitter-card-title">' . esc_html(__('Title')) . '</label></th>';
         echo '<td><input type="text" id="twitter-card-title" name="' . esc_attr(static::META_KEY . '[' . static::TITLE_KEY . ']') . '" maxlength="70" autocomplete="off"';
         if (isset($stored_values[static::TITLE_KEY])) {
             echo ' value="' . esc_attr($stored_values[static::TITLE_KEY]) . '"';
         } else {
             echo ' placeholder="' . esc_attr(get_the_title($post)) . '"';
         }
         echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '></td>';
         echo '</tr>';
     }
     if (isset($cards_fields_supported_by_post_type[static::DESCRIPTION_KEY])) {
         echo '<tr>';
         echo '<th scope="row" class="left"><label for="twitter-card-description">' . esc_html(__('Description')) . '</label></th>';
         echo '<td><input type="text" id="twitter-card-description" name="' . esc_attr(static::META_KEY . '[' . static::DESCRIPTION_KEY . ']') . '" maxlength="200" autocomplete="off"';
         if (isset($stored_values[static::DESCRIPTION_KEY])) {
             echo ' value="' . esc_attr($stored_values[static::DESCRIPTION_KEY]) . '"';
         }
         echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '></td>';
         echo '</tr>';
         echo '</tbody></table>';
         echo '<p class="description">' . esc_html(__('Customize Twitter link previews', 'twitter')) . '</p>';
     }
 }
Ejemplo n.º 8
0
 /**
  * Suppress a Content Security Policy warning
  *
  * @since 1.0.0
  *
  * @return void
  */
 public function displayContentSecurityPolicy()
 {
     $key = 'csp';
     echo '<label><input type="checkbox" name="' . esc_attr(self::OPTION_NAME . '[' . $key . ']') . '" value="1"';
     checked(isset($this->existing_options[$key]));
     echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>';
     echo esc_html(__('Suppress Content Security Policy warnings', 'twitter'));
     echo '</label>';
     echo '<p class="description">';
     echo sprintf(esc_html(__('Please note: Not all widget functionality is supported when a %s is applied', 'twitter')), '<a href="' . esc_url('https://developer.mozilla.org/docs/Web/Security/CSP/Introducing_Content_Security_Policy', array('https', 'http')) . '">' . esc_html(__('Content Security Policy', 'twitter')) . '</a>');
     echo '</p>';
 }
Ejemplo n.º 9
0
 /**
  * Proactively resolve Twitter widget JS FQDN asynchronously before later use
  *
  * @since 1.0.0
  *
  * @link http://dev.chromium.org/developers/design-documents/dns-prefetching Chromium prefetch behavior
  * @link https://developer.mozilla.org/en-US/docs/Controlling_DNS_prefetching Firefox prefetch behavior
  *
  * @return void
  */
 public static function dnsPrefetch()
 {
     echo '<link rel="dns-prefetch" href="//platform.twitter.com"';
     echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement();
     echo '>' . "\n";
 }
Ejemplo n.º 10
0
 /**
  * Track a Twitter advertising event using 1x1 images
  *
  * @since 1.0.0
  *
  * @param string $tracking_id Twitter ads tracking ID
  *
  * @return void
  */
 protected static function trackEventUsingFallbackImages($tracking_id)
 {
     $query_parameters = http_build_query(array('txn_id' => $tracking_id, 'p_id' => 'Twitter'), '', '&');
     echo '<img height="1" width="1" alt=" " src="' . esc_url('https://analytics.twitter.com/i/adsct?' . $query_parameters, array('https', 'http')) . '"' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>';
     echo '<img height="1" width="1" alt=" " src="' . esc_url('https://t.co/i/adsct?' . $query_parameters, array('https', 'http')) . '"' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>';
 }
Ejemplo n.º 11
0
 /**
  * Input a Twitter screen_name to attribute to site content
  *
  * @since 1.0.0
  *
  * @return void
  */
 public function displaySiteAttributionUsername()
 {
     $html = '<input type="text" id="' . esc_attr(self::OPTION_NAME) . '" name="' . esc_attr(self::OPTION_NAME) . '" size="20"';
     $site_username = get_option(self::OPTION_NAME);
     if ($site_username) {
         $html .= ' value="' . esc_attr($site_username) . '"';
     }
     $html .= \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>';
     // escaped in markup builder
     // @codingStandardsIgnoreStart WordPress.XSS.EscapeOutput
     echo $html;
     // @codingStandardsIgnoreEnd WordPress.XSS.EscapeOutput
 }
Ejemplo n.º 12
0
    /**
     * Settings update form
     *
     * @since 1.3.0
     *
     * @param array $instance Current settings
     *
     * @return void
     */
    public function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array_merge(array('title' => ''), \Twitter\WordPress\Shortcodes\PeriscopeOnAir::$SHORTCODE_DEFAULTS));
        $close_void_element = \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement();
        ?>
		<p><label for="<?php 
        echo esc_attr($this->get_field_id('title'));
        ?>
"><?php 
        echo esc_html(__('Title:', 'twitter'));
        ?>
</label>
		<input class="widefat" id="<?php 
        echo esc_attr($this->get_field_id('title'));
        ?>
" name="<?php 
        echo esc_attr($this->get_field_name('title'));
        ?>
" type="text" value="<?php 
        echo esc_attr(trim(strip_tags($instance['title'])));
        ?>
"<?php 
        echo $close_void_element;
        ?>
></p>

		<p><label for="<?php 
        echo esc_attr($this->get_field_id('username'));
        ?>
"><?php 
        echo esc_html(__('Periscope username', 'twitter'));
        ?>
</label>
		<input class="widefat" id="<?php 
        echo esc_attr($this->get_field_id('username'));
        ?>
" name="<?php 
        echo esc_attr($this->get_field_name('username'));
        ?>
" type="text" pattern="[a-zA-Z0-9_]{1,20}" value="<?php 
        echo esc_attr($instance['username']);
        ?>
"<?php 
        echo $close_void_element;
        ?>
></p>

		<p><label for="<?php 
        echo esc_attr($this->get_field_id('size'));
        ?>
"><?php 
        echo esc_html(__('Button size:', 'twitter'));
        ?>
</label>
		<fieldset id="<?php 
        echo esc_attr($this->get_field_id('size'));
        ?>
">
			<label><input type="radio" name="<?php 
        echo esc_attr($this->get_field_name('size'));
        ?>
" value="small"<?php 
        checked('large' != $instance['size']);
        echo $close_void_element;
        ?>
> <?php 
        echo esc_html(_x('small', 'small size button', 'twitter'));
        ?>
 </label>
			<label><input type="radio" name="<?php 
        echo esc_attr($this->get_field_name('size'));
        ?>
" value="large"<?php 
        checked('large' == $instance['size']);
        echo $close_void_element;
        ?>
> <?php 
        echo esc_html(_x('large', 'large size button', 'twitter'));
        ?>
 </label>
		</fieldset></p>
<?php 
    }
Ejemplo n.º 13
0
 /**
  * Control display of the total number of Tweets citing the Tweet URL
  *
  * @since 1.0.0
  *
  * @return void
  */
 public function displayCount()
 {
     $key = 'count';
     echo '<label><input type="checkbox" name="' . esc_attr(static::OPTION_NAME . '[' . $key . ']') . '" value="1"';
     if (!(isset($this->existing_options) && isset($this->existing_options[$key]) && 'none' === $this->existing_options[$key])) {
         echo ' checked';
         if (!current_theme_supports('html5')) {
             echo '="checked"';
         }
     }
     echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '> ' . esc_html(__('Show the number of Tweets citing the post URL', 'twitter')) . '</label>';
 }
Ejemplo n.º 14
0
 /**
  * Choose a large button size, overriding the default
  *
  * @since 1.0.0
  *
  * @return void
  */
 public function displaySize()
 {
     $key = 'size';
     echo '<label><input type="checkbox" name="' . esc_attr(static::OPTION_NAME . '[' . $key . ']') . '" value="large"';
     if (isset($this->existing_options) && isset($this->existing_options[$key]) && 'large' === $this->existing_options[$key]) {
         echo ' checked';
         if (!current_theme_supports('html5')) {
             echo '="checked"';
         }
     }
     echo \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '> ' . esc_html(__('Large button', 'twitter')) . '</label>';
 }
Ejemplo n.º 15
0
 /**
  * Proactively resolve FQDN DNS using a resource hint link
  *
  * @since 1.5.0
  *
  * @return void
  */
 public static function printDNSPrefetchElement()
 {
     echo '<link rel="dns-prefetch" href="//' . esc_attr(static::FQDN) . '"' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>' . "\n";
 }