Example #1
0
 /**
  * Register JavaScript during the enqueue scripts action
  *
  * @since 1.0.0
  *
  * @return void
  */
 public static function registerScripts()
 {
     // widgets.js
     \Twitter\WordPress\JavaScriptLoaders\Widgets::register();
     // ad tracker
     \Twitter\WordPress\JavaScriptLoaders\Tracking::register();
 }
Example #2
0
 /**
  * Handle shortcode macro
  *
  * @since 1.0.0
  *
  * @param array  $attributes shortcode attributes
  * @param string $content    shortcode content. no effect
  *
  * @return string Tweet button HTML or empty string
  */
 public static function shortcodeHandler($attributes, $content = null)
 {
     // clean up attribute to shortcode option mappings before passing to filter
     // apply the same filter as shortcode_atts
     /** This filter is documented in wp-includes/shortcodes.php */
     $options = apply_filters('shortcode_atts_' . self::SHORTCODE_TAG, array_merge(static::$SHORTCODE_DEFAULTS, static::sanitizeShortcodeParameters((array) $attributes)), static::$SHORTCODE_DEFAULTS, $attributes);
     // add options shared to post meta
     $options = static::addPostMetaOptions($options);
     //  add parameters based on per-post render context
     if (in_the_loop()) {
         $post = get_post();
         // do not share posts requiring a password to access
         if ($post && !empty($post->post_password)) {
             return '';
         }
         // protect sites from themselves
         // do not display Tweet button for non-public content to avoid leaking content
         $post_status_object = get_post_status_object(get_post_status($post));
         if (!($post_status_object && isset($post_status_object->public) && $post_status_object->public)) {
             return '';
         }
         unset($post_status_object);
         // add parameters based on post data
         $options = static::addPostData($options, $post);
         unset($post);
     }
     if (!(isset($options['via']) && $options['via'])) {
         // attribute the Tweet to the site Twitter username
         $via_username = \Twitter\WordPress\Site\Username::getViaAttribution(in_the_loop() ? get_the_ID() : null);
         if ($via_username) {
             $options['via'] = $via_username;
         }
         unset($via_username);
     }
     $button = \Twitter\Widgets\TweetButton::fromArray($options);
     if (!$button) {
         return '';
     }
     $html = $button->toHTML(_x('Tweet', 'Tweet verb. Sharing.', 'twitter'), '\\Twitter\\WordPress\\Helpers\\HTMLBuilder');
     if (!$html) {
         return '';
     }
     \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue();
     return '<div class="twitter-share">' . $html . '</div>';
 }
 /**
  * Handle shortcode macro
  *
  * @since 1.0.0
  *
  * @param array  $attributes shortcode attributes
  * @param string $content    shortcode content. no effect
  *
  * @return string HTML markup
  */
 public static function shortcodeHandler($attributes, $content = '')
 {
     // clean up attribute to shortcode option mappings before passing to filter
     // apply the same filter as shortcode_atts
     /** This filter is documented in wp-includes/shortcodes.php */
     $options = apply_filters('shortcode_atts_' . self::SHORTCODE_TAG, array_merge(static::$SHORTCODE_DEFAULTS, static::sanitizeShortcodeParameters((array) $attributes)), static::$SHORTCODE_DEFAULTS, $attributes);
     if (!$options['id']) {
         return '';
     }
     $tweet_id = $options['id'];
     unset($options['id']);
     $oembed_params = static::shortcodeParamsToOEmbedParams($tweet_id, $options);
     if (empty($oembed_params)) {
         return '';
     }
     // fetch HTML markup from Twitter oEmbed endpoint for the given parameters
     $html = trim(static::getOEmbedMarkup($oembed_params));
     if (!$html) {
         return '';
     }
     $html = '<div class="twitter-video">' . $html . '</div>';
     $inline_js = \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue();
     if ($inline_js) {
         return $html . $inline_js;
     }
     return $html;
 }
Example #4
0
 /**
  * Handle shortcode macro
  *
  * @since 1.3.0
  *
  * @param array  $attributes set of shortcode attribute-value pairs or positional content matching the WordPress shortcode regex {
  *   @type string|int attribute name or positional int
  *   @type mixed      shortcode value
  * }
  * @param string $content    content inside a shortcode macro. no effect on this shortcode
  *
  * @return string HTML markup. empty string if parameter requirement not met or no collection info found
  */
 public static function shortcodeHandler($attributes, $content = '')
 {
     $options = shortcode_atts(static::$SHORTCODE_DEFAULTS, $attributes, static::SHORTCODE_TAG);
     $snowflake_id = trim($options['id']);
     if (!$snowflake_id) {
         return '';
     }
     $query_parameters = static::getBaseOEmbedParams($snowflake_id);
     if (isset($options['limit'])) {
         $limit = 0;
         try {
             $limit = intval(trim($options['limit']), 10);
         } catch (Exception $e) {
         }
         if ($limit > 0 && $limit < 20) {
             $query_parameters['limit'] = $limit;
         }
     }
     // fetch HTML markup from Twitter oEmbed endpoint for the given parameters
     $html = trim(static::getOEmbedMarkup($query_parameters));
     if (!$html) {
         return '';
     }
     $html = '<div class="' . sanitize_html_class(static::HTML_CLASS) . '">' . $html . '</div>';
     $inline_js = \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue();
     if ($inline_js) {
         return $html . $inline_js;
     }
     return $html;
 }
Example #5
0
 /**
  * Handle shortcode macro
  *
  * @since 1.0.0
  *
  * @param array  $attributes shortcode attributes
  * @param string $content    shortcode content. no effect
  *
  * @return string Follow button HTML or empty string
  */
 public static function shortcodeHandler($attributes, $content = '')
 {
     // clean up attribute to shortcode option mappings before passing to filter
     // apply the same filter as shortcode_atts
     /** This filter is documented in wp-includes/shortcodes.php */
     $options = apply_filters('shortcode_atts_' . self::SHORTCODE_TAG, array_merge(static::$SHORTCODE_DEFAULTS, static::sanitizeShortcodeParameters((array) $attributes)), static::$SHORTCODE_DEFAULTS, $attributes);
     $screen_name = '';
     if (isset($options['screen_name'])) {
         $screen_name = $options['screen_name'];
         unset($options['screen_name']);
     }
     if (!$screen_name) {
         $screen_name = static::getScreenName();
         // follow target required
         if (!$screen_name) {
             return '';
         }
     }
     // update the options array with the Follow screen name
     $options['screen_name'] = $screen_name;
     $follow = \Twitter\Widgets\FollowButton::fromArray($options);
     if (!$follow) {
         return '';
     }
     $html = $follow->toHTML(_x('Follow %s', 'Follow a Twitter user', 'twitter'), '\\Twitter\\WordPress\\Helpers\\HTMLBuilder');
     if (!$html) {
         return '';
     }
     \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue();
     return '<div class="twitter-follow">' . $html . '</div>';
 }
Example #6
0
 /**
  * Register JavaScript during the enqueue scripts action
  *
  * @since 1.0.0
  *
  * @return void
  */
 public static function registerScripts()
 {
     // Twitter widgets
     \Twitter\WordPress\JavaScriptLoaders\Widgets::register();
     // Vine embed
     \Twitter\WordPress\JavaScriptLoaders\VineEmbed::register();
     // Twitter audience tracker and conversion
     \Twitter\WordPress\JavaScriptLoaders\Tracking::register();
 }
Example #7
0
 /**
  * Handle shortcode macro
  *
  * @since 1.3.0
  *
  * @param array  $attributes shortcode attributes
  * @param string $content    shortcode content. no effect
  *
  * @return string Periscope On Air button HTML or empty string
  */
 public static function shortcodeHandler($attributes, $content = '')
 {
     // clean up attribute to shortcode option mappings before passing to filter
     // apply the same filter as shortcode_atts
     /** This filter is documented in wp-includes/shortcodes.php */
     $options = apply_filters('shortcode_atts_' . self::SHORTCODE_TAG, array_merge(static::$SHORTCODE_DEFAULTS, static::sanitizeShortcodeParameters((array) $attributes)), static::$SHORTCODE_DEFAULTS, $attributes);
     $username = '';
     if (isset($options['username'])) {
         $username = $options['username'];
         unset($options['username']);
     }
     if (!$username) {
         $username = static::getUsername();
         // user target required
         if (!$username) {
             return '';
         }
     }
     // update the options array with the Periscope username
     $options['username'] = $username;
     unset($username);
     $on_air = \Twitter\Widgets\PeriscopeOnAir::fromArray($options);
     if (!$on_air) {
         return '';
     }
     $html = $on_air->toHTML('\\Twitter\\WordPress\\Helpers\\HTMLBuilder');
     if (!$html) {
         return '';
     }
     $html = '<div class="periscope-on-air">' . $html . '</div>';
     $inline_js = \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue();
     if ($inline_js) {
         return $html . $inline_js;
     }
     return $html;
 }