1 | <?php |
||
21 | class Jetpack_Tweet { |
||
22 | |||
23 | static $provider_args; |
||
|
|||
24 | |||
25 | /** |
||
26 | * Parse shortcode arguments and render its output. |
||
27 | * |
||
28 | * @since 4.5.0 |
||
29 | * |
||
30 | * @param array $atts Shortcode parameters. |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | static public function jetpack_tweet_shortcode( $atts ) { |
||
35 | $default_atts = array( |
||
36 | 'tweet' => '', |
||
37 | 'align' => 'none', |
||
38 | 'width' => '', |
||
39 | 'lang' => 'en', |
||
40 | 'hide_thread' => 'false', |
||
41 | 'hide_media' => 'false', |
||
42 | ); |
||
43 | |||
44 | $attr = shortcode_atts( $default_atts, $atts ); |
||
45 | |||
46 | self::$provider_args = $attr; |
||
47 | |||
48 | // figure out the tweet id for the requested tweet |
||
49 | // supporting both omitted attributes and tweet="tweet_id" |
||
50 | // and supporting both an id and a URL |
||
51 | if ( empty( $attr['tweet'] ) && ! empty( $atts[0] ) ) { |
||
52 | $attr['tweet'] = $atts[0]; |
||
53 | } |
||
54 | |||
55 | preg_match( '/^http(s|):\/\/twitter\.com(\/\#\!\/|\/)([a-zA-Z0-9_]{1,20})\/status(es)*\/(\d+)$/', $attr['tweet'], $urlbits ); |
||
56 | if ( isset( $urlbits[5] ) && intval( $urlbits[5] ) ) { |
||
57 | $id = 'https://twitter.com/' . $urlbits[3] . '/status/' . intval( $urlbits[5] ); |
||
58 | } else { |
||
59 | return '<!-- Invalid tweet id -->'; |
||
60 | } |
||
61 | |||
62 | // Add shortcode arguments to provider URL |
||
63 | add_filter( 'oembed_fetch_url', array( 'Jetpack_Tweet', 'jetpack_tweet_url_extra_args' ), 10, 3 ); |
||
64 | |||
65 | // Fetch tweet |
||
66 | $output = wp_oembed_get( $id, $atts ); |
||
67 | |||
68 | // Clean up filter |
||
69 | remove_filter( 'oembed_fetch_url', array( 'Jetpack_Tweet', 'jetpack_tweet_url_extra_args' ), 10 ); |
||
70 | |||
71 | // Add Twitter widgets.js script to the footer. |
||
72 | add_action( 'wp_footer', array( 'Jetpack_Tweet', 'jetpack_tweet_shortcode_script' ) ); |
||
73 | |||
74 | /** This action is documented in modules/widgets/social-media-icons.php */ |
||
75 | do_action( 'jetpack_bump_stats_extras', 'embeds', 'tweet' ); |
||
76 | |||
77 | return $output; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Adds parameters to URL used to fetch the tweet. |
||
82 | * |
||
83 | * @since 4.5.0 |
||
84 | * |
||
85 | * @param string $provider URL of provider that supplies the tweet we're requesting. |
||
86 | * @param string $url URL of tweet to embed. |
||
87 | * @param array $args Parameters supplied to shortcode and passed to wp_oembed_get |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | static public function jetpack_tweet_url_extra_args( $provider, $url, $args = array() ) { |
||
111 | |||
112 | /** |
||
113 | * Enqueue front end assets. |
||
114 | * |
||
115 | * @since 4.5.0 |
||
116 | */ |
||
117 | static public function jetpack_tweet_shortcode_script() { |
||
123 | |||
124 | } // class end |
||
125 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.