Since: 1.0.0
Inheritance: implements Twitter\WordPress\Shortcodes\ShortcodeInterface, implements Twitter\WordPress\Shortcodes\PublishOEmbedEndpoint, use trait Twitter\WordPress\Shortcodes\OEmbedTrait
Ejemplo n.º 1
0
 /**
  * Test building a unique cache key for requested query parameters
  *
  * @since 1.0.0
  *
  * @covers ::oEmbedCacheKey
  * @small
  *
  * @return void
  */
 public function testOEmbedCacheKey()
 {
     $this->assertEquals('tweet_20', \Twitter\WordPress\Shortcodes\EmbeddedTweet::oEmbedCacheKey(array('id' => '20')), 'Unexpected cache key');
 }
Ejemplo n.º 2
0
 /**
  * Convert shortcode parameters, attributes, and defaults into a clean set of Tweet parameters
  *
  * @since 1.0.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
  * }
  *
  * @return array cleaned up options ready for comparison {
  *   @type string option name
  *   @type string|bool option value
  * }
  */
 public static function sanitizeShortcodeParameters($attributes = array())
 {
     if (!is_array($attributes)) {
         return array();
     }
     $options = array();
     if (isset($attributes['in_reply_to'])) {
         $tweet_id = \Twitter\WordPress\Shortcodes\EmbeddedTweet::sanitizeTweetID((string) $attributes['in_reply_to']);
         if ($tweet_id) {
             $options['in_reply_to'] = $tweet_id;
         }
         unset($tweet_id);
     }
     if (isset($attributes['text']) && is_string($attributes['text'])) {
         $options['text'] = $attributes['text'];
     }
     foreach (array('url', 'counturl') as $url_param) {
         if (!(isset($attributes[$url_param]) && $attributes[$url_param])) {
             continue;
         }
         // filter the URL
         $url = esc_url_raw(trim($attributes[$url_param]), array('http', 'https'));
         if ($url) {
             $options[$url_param] = $url;
         }
         unset($url);
     }
     if (isset($attributes['related'])) {
         $intent = \Twitter\Intents\Tweet::fromArray(array('related' => $attributes['related']));
         if ($intent) {
             $related = $intent->getRelated();
             if (!empty($related)) {
                 $options['related'] = $related;
             }
             unset($related);
         }
         unset($intent);
     }
     if (isset($attributes['via'])) {
         $via = (new \Twitter\Intents\Tweet())->setVia($attributes['via'])->getVia();
         if ($via) {
             $options['via'] = $via;
         }
         unset($via);
     }
     if (isset($attributes['hashtags'])) {
         $intent = \Twitter\Intents\Tweet::fromArray(array('hashtags' => $attributes['hashtags']));
         if ($intent) {
             $hashtags = $intent->getHashtags();
             if (!empty($hashtags)) {
                 $options['hashtags'] = $hashtags;
             }
             unset($hashtags);
         }
         unset($intent);
     }
     if (isset($attributes['align']) && is_string($attributes['align']) && $attributes['align']) {
         $align = strtolower(trim($attributes['align']));
         if (array_key_exists($align, \Twitter\Widgets\TweetButton::$ALLOWED_ALIGN_VALUES)) {
             $options['align'] = $align;
         }
         unset($align);
     }
     if (isset($attributes['count']) && is_string($attributes['count'])) {
         $count = strtolower(trim($attributes['count']));
         if (array_key_exists($count, \Twitter\Widgets\TweetButton::$ALLOWED_COUNT_VALUES)) {
             $options['count'] = $count;
         }
         unset($count);
     }
     // large is the only option
     if (isset($attributes['size'])) {
         if (is_string($attributes['size']) && in_array(strtolower($attributes['size']), array('large', 'l'))) {
             $options['size'] = 'large';
         }
     }
     return $options;
 }
Ejemplo n.º 3
0
 /**
  * Convert shortcode parameters, attributes, and defaults into a clean set of Tweet parameters
  *
  * @since 1.0.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
  * }
  *
  * @return array cleaned up options ready for comparison {
  *   @type string option name
  *   @type string|bool option value
  * }
  */
 public static function sanitizeShortcodeParameters($attributes = array())
 {
     if (!is_array($attributes)) {
         return array();
     }
     $options = array();
     if (isset($attributes['in_reply_to'])) {
         $tweet_id = \Twitter\WordPress\Shortcodes\EmbeddedTweet::sanitizeTweetID((string) $attributes['in_reply_to']);
         if ($tweet_id) {
             $options['in_reply_to'] = $tweet_id;
         }
         unset($tweet_id);
     }
     if (isset($attributes['text']) && is_string($attributes['text'])) {
         $options['text'] = $attributes['text'];
     }
     if (isset($attributes['url']) && $attributes['url']) {
         $url = esc_url_raw(trim($attributes['url']), array('http', 'https'));
         if ($url) {
             $options['url'] = $url;
         }
         unset($url);
     }
     if (isset($attributes['related'])) {
         $intent = \Twitter\Intents\Tweet::fromArray(array('related' => $attributes['related']));
         if ($intent) {
             $related = $intent->getRelated();
             if (!empty($related)) {
                 $options['related'] = $related;
             }
             unset($related);
         }
         unset($intent);
     }
     if (isset($attributes['via'])) {
         $via = (new \Twitter\Intents\Tweet())->setVia($attributes['via'])->getVia();
         if ($via) {
             $options['via'] = $via;
         }
         unset($via);
     }
     if (isset($attributes['hashtags'])) {
         $intent = \Twitter\Intents\Tweet::fromArray(array('hashtags' => $attributes['hashtags']));
         if ($intent) {
             $hashtags = $intent->getHashtags();
             if (!empty($hashtags)) {
                 $options['hashtags'] = $hashtags;
             }
             unset($hashtags);
         }
         unset($intent);
     }
     // large is the only option
     if (isset($attributes['size'])) {
         if (is_string($attributes['size']) && in_array(strtolower($attributes['size']), array('large', 'l'))) {
             $options['size'] = 'large';
         }
     }
     return $options;
 }