[a-zA-Z0-9_]{1,20})\/status(?:es)?\/(?P\d+)#i'; /** * URL pattern for a Twitter timeline. * * @since 1.0 * @var string */ const URL_PATTERN_TIMELINE = '#https?:\/\/twitter\.com(?:\/\#\!\/|\/)(?P[a-zA-Z0-9_]{1,20})(?:$|\/(?Plikes|lists)(\/(?P[a-zA-Z0-9_-]+))?)#i'; /** * Tag. * * @var string embed HTML blockquote tag to identify and replace with AMP version. */ protected $sanitize_tag = 'blockquote'; /** * Tag. * * @var string AMP amp-facebook tag */ private $amp_tag = 'amp-twitter'; /** * Registers embed. */ public function register_embed() { wp_embed_register_handler( 'amp-twitter-timeline', self::URL_PATTERN_TIMELINE, [ $this, 'oembed_timeline' ], -1 ); } /** * Unregisters embed. */ public function unregister_embed() { wp_embed_unregister_handler( 'amp-twitter-timeline', -1 ); } /** * Render oEmbed for a timeline. * * @since 1.0 * * @param array $matches URL pattern matches. * @return string Rendered oEmbed. */ public function oembed_timeline( $matches ) { if ( ! isset( $matches['username'] ) ) { return ''; } $attributes = [ 'data-timeline-source-type' => 'profile', 'data-timeline-screen-name' => $matches['username'], ]; if ( isset( $matches['type'] ) ) { switch ( $matches['type'] ) { case 'likes': $attributes['data-timeline-source-type'] = 'likes'; break; case 'lists': if ( ! isset( $matches['id'] ) ) { return ''; } $attributes['data-timeline-source-type'] = 'list'; $attributes['data-timeline-slug'] = $matches['id']; $attributes['data-timeline-owner-screen-name'] = $attributes['data-timeline-screen-name']; unset( $attributes['data-timeline-screen-name'] ); break; default: return ''; } } if ( ! empty( $this->args['width'] ) ) { $attributes['width'] = $this->args['width']; } $attributes['height'] = $this->args['height']; if ( empty( $attributes['width'] ) || 'auto' === $attributes['width'] ) { $attributes['layout'] = 'fixed-height'; } else { $attributes['layout'] = 'responsive'; } $this->did_convert_elements = true; return AMP_HTML_Utils::build_tag( $this->amp_tag, $attributes, $this->create_overflow_button_markup() ); } /** * Sanitized