changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
8:c7c34916027a | 9:177826044cd9 |
---|---|
28 |
28 |
29 /** |
29 /** |
30 * A list of an early oEmbed providers. |
30 * A list of an early oEmbed providers. |
31 * |
31 * |
32 * @since 4.0.0 |
32 * @since 4.0.0 |
33 * @static |
|
34 * @var array |
33 * @var array |
35 */ |
34 */ |
36 public static $early_providers = array(); |
35 public static $early_providers = array(); |
37 |
36 |
38 /** |
37 /** |
47 * Constructor. |
46 * Constructor. |
48 * |
47 * |
49 * @since 2.9.0 |
48 * @since 2.9.0 |
50 */ |
49 */ |
51 public function __construct() { |
50 public function __construct() { |
52 $host = urlencode( home_url() ); |
51 $host = urlencode( home_url() ); |
53 $providers = array( |
52 $providers = array( |
54 '#https?://((m|www)\.)?youtube\.com/watch.*#i' => array( 'https://www.youtube.com/oembed', true ), |
53 '#https?://((m|www)\.)?youtube\.com/watch.*#i' => array( 'https://www.youtube.com/oembed', true ), |
55 '#https?://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'https://www.youtube.com/oembed', true ), |
54 '#https?://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'https://www.youtube.com/oembed', true ), |
56 '#https?://youtu\.be/.*#i' => array( 'https://www.youtube.com/oembed', true ), |
55 '#https?://youtu\.be/.*#i' => array( 'https://www.youtube.com/oembed', true ), |
57 '#https?://(.+\.)?vimeo\.com/.*#i' => array( 'https://vimeo.com/api/oembed.{format}', true ), |
56 '#https?://(.+\.)?vimeo\.com/.*#i' => array( 'https://vimeo.com/api/oembed.{format}', true ), |
58 '#https?://(www\.)?dailymotion\.com/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ), |
57 '#https?://(www\.)?dailymotion\.com/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ), |
59 '#https?://dai\.ly/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ), |
58 '#https?://dai\.ly/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ), |
60 '#https?://(www\.)?flickr\.com/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ), |
59 '#https?://(www\.)?flickr\.com/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ), |
61 '#https?://flic\.kr/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ), |
60 '#https?://flic\.kr/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ), |
62 '#https?://(.+\.)?smugmug\.com/.*#i' => array( 'https://api.smugmug.com/services/oembed/', true ), |
61 '#https?://(.+\.)?smugmug\.com/.*#i' => array( 'https://api.smugmug.com/services/oembed/', true ), |
63 '#https?://(www\.)?hulu\.com/watch/.*#i' => array( 'http://www.hulu.com/api/oembed.{format}', true ), |
62 '#https?://(www\.)?hulu\.com/watch/.*#i' => array( 'http://www.hulu.com/api/oembed.{format}', true ), |
64 'http://i*.photobucket.com/albums/*' => array( 'http://api.photobucket.com/oembed', false ), |
63 '#https?://(www\.)?scribd\.com/(doc|document)/.*#i' => array( 'https://www.scribd.com/services/oembed', true ), |
65 'http://gi*.photobucket.com/groups/*' => array( 'http://api.photobucket.com/oembed', false ), |
64 '#https?://wordpress\.tv/.*#i' => array( 'https://wordpress.tv/oembed/', true ), |
66 '#https?://(www\.)?scribd\.com/doc/.*#i' => array( 'https://www.scribd.com/services/oembed', true ), |
65 '#https?://(.+\.)?polldaddy\.com/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ), |
67 '#https?://wordpress\.tv/.*#i' => array( 'https://wordpress.tv/oembed/', true ), |
66 '#https?://poll\.fm/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ), |
68 '#https?://(.+\.)?polldaddy\.com/.*#i' => array( 'https://polldaddy.com/oembed/', true ), |
67 '#https?://(.+\.)?survey\.fm/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ), |
69 '#https?://poll\.fm/.*#i' => array( 'https://polldaddy.com/oembed/', true ), |
68 '#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i' => array( 'https://publish.twitter.com/oembed', true ), |
70 '#https?://(www\.)?funnyordie\.com/videos/.*#i' => array( 'http://www.funnyordie.com/oembed', true ), |
69 '#https?://(www\.)?twitter\.com/\w{1,15}$#i' => array( 'https://publish.twitter.com/oembed', true ), |
71 '#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i' => array( 'https://publish.twitter.com/oembed', true ), |
70 '#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i' => array( 'https://publish.twitter.com/oembed', true ), |
72 '#https?://(www\.)?twitter\.com/\w{1,15}$#i' => array( 'https://publish.twitter.com/oembed', true ), |
71 '#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i' => array( 'https://publish.twitter.com/oembed', true ), |
73 '#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i' => array( 'https://publish.twitter.com/oembed', true ), |
72 '#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i' => array( 'https://publish.twitter.com/oembed', true ), |
74 '#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i' => array( 'https://publish.twitter.com/oembed', true ), |
73 '#https?://(www\.)?twitter\.com/i/moments/.*#i' => array( 'https://publish.twitter.com/oembed', true ), |
75 '#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i' => array( 'https://publish.twitter.com/oembed', true ), |
74 '#https?://(www\.)?soundcloud\.com/.*#i' => array( 'https://soundcloud.com/oembed', true ), |
76 '#https?://(www\.)?twitter\.com/i/moments/.*#i' => array( 'https://publish.twitter.com/oembed', true ), |
75 '#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ), |
77 '#https?://(www\.)?soundcloud\.com/.*#i' => array( 'https://soundcloud.com/oembed', true ), |
76 '#https?://(www\.)?instagr(\.am|am\.com)/(p|tv)/.*#i' => array( 'https://api.instagram.com/oembed', true ), |
78 '#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ), |
77 '#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ), |
79 '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' => array( 'https://api.instagram.com/oembed', true ), |
78 '#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true ), |
80 '#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ), |
79 '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i' => array( 'https://api.meetup.com/oembed', true ), |
81 '#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true ), |
80 '#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true ), |
82 '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i' => array( 'https://api.meetup.com/oembed', true ), |
81 '#https?://(www\.)?collegehumor\.com/video/.*#i' => array( 'https://www.collegehumor.com/oembed.{format}', true ), |
83 '#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true ), |
82 '#https?://(www\.)?mixcloud\.com/.*#i' => array( 'https://www.mixcloud.com/oembed', true ), |
84 '#https?://(www\.)?collegehumor\.com/video/.*#i' => array( 'https://www.collegehumor.com/oembed.{format}', true ), |
83 '#https?://(www\.|embed\.)?ted\.com/talks/.*#i' => array( 'https://www.ted.com/services/v1/oembed.{format}', true ), |
85 '#https?://(www\.)?mixcloud\.com/.*#i' => array( 'https://www.mixcloud.com/oembed', true ), |
84 '#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'https://animoto.com/oembeds/create', true ), |
86 '#https?://(www\.|embed\.)?ted\.com/talks/.*#i' => array( 'https://www.ted.com/services/v1/oembed.{format}', true ), |
85 '#https?://(.+)\.tumblr\.com/post/.*#i' => array( 'https://www.tumblr.com/oembed/1.0', true ), |
87 '#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'https://animoto.com/oembeds/create', true ), |
86 '#https?://(www\.)?kickstarter\.com/projects/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ), |
88 '#https?://(.+)\.tumblr\.com/post/.*#i' => array( 'https://www.tumblr.com/oembed/1.0', true ), |
87 '#https?://kck\.st/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ), |
89 '#https?://(www\.)?kickstarter\.com/projects/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ), |
88 '#https?://cloudup\.com/.*#i' => array( 'https://cloudup.com/oembed', true ), |
90 '#https?://kck\.st/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ), |
89 '#https?://(www\.)?reverbnation\.com/.*#i' => array( 'https://www.reverbnation.com/oembed', true ), |
91 '#https?://cloudup\.com/.*#i' => array( 'https://cloudup.com/oembed', true ), |
90 '#https?://videopress\.com/v/.*#' => array( 'https://public-api.wordpress.com/oembed/?for=' . $host, true ), |
92 '#https?://(www\.)?reverbnation\.com/.*#i' => array( 'https://www.reverbnation.com/oembed', true ), |
91 '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i' => array( 'https://www.reddit.com/oembed', true ), |
93 '#https?://videopress\.com/v/.*#' => array( 'https://public-api.wordpress.com/oembed/?for=' . $host, true ), |
92 '#https?://(www\.)?speakerdeck\.com/.*#i' => array( 'https://speakerdeck.com/oembed.{format}', true ), |
94 '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i' => array( 'https://www.reddit.com/oembed', true ), |
93 '#https?://www\.facebook\.com/.*/posts/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
95 '#https?://(www\.)?speakerdeck\.com/.*#i' => array( 'https://speakerdeck.com/oembed.{format}', true ), |
94 '#https?://www\.facebook\.com/.*/activity/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
96 '#https?://www\.facebook\.com/.*/posts/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
95 '#https?://www\.facebook\.com/.*/photos/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
97 '#https?://www\.facebook\.com/.*/activity/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
96 '#https?://www\.facebook\.com/photo(s/|\.php).*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
98 '#https?://www\.facebook\.com/.*/photos/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
97 '#https?://www\.facebook\.com/permalink\.php.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
99 '#https?://www\.facebook\.com/photo(s/|\.php).*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
98 '#https?://www\.facebook\.com/media/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
100 '#https?://www\.facebook\.com/permalink\.php.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
99 '#https?://www\.facebook\.com/questions/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
101 '#https?://www\.facebook\.com/media/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
100 '#https?://www\.facebook\.com/notes/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
102 '#https?://www\.facebook\.com/questions/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
101 '#https?://www\.facebook\.com/.*/videos/.*#i' => array( 'https://www.facebook.com/plugins/video/oembed.json/', true ), |
103 '#https?://www\.facebook\.com/notes/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), |
102 '#https?://www\.facebook\.com/video\.php.*#i' => array( 'https://www.facebook.com/plugins/video/oembed.json/', true ), |
104 '#https?://www\.facebook\.com/.*/videos/.*#i' => array( 'https://www.facebook.com/plugins/video/oembed.json/', true ), |
103 '#https?://(www\.)?screencast\.com/.*#i' => array( 'https://api.screencast.com/external/oembed', true ), |
105 '#https?://www\.facebook\.com/video\.php.*#i' => array( 'https://www.facebook.com/plugins/video/oembed.json/', true ), |
104 '#https?://([a-z0-9-]+\.)?amazon\.(com|com\.mx|com\.br|ca)/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), |
106 '#https?://(www\.)?screencast\.com/.*#i' => array( 'https://api.screencast.com/external/oembed', true ), |
105 '#https?://([a-z0-9-]+\.)?amazon\.(co\.uk|de|fr|it|es|in|nl|ru)/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ), |
107 '#https?://([a-z0-9-]+\.)?amazon\.(com|com\.mx|com\.br|ca)/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), |
106 '#https?://([a-z0-9-]+\.)?amazon\.(co\.jp|com\.au)/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ), |
108 '#https?://([a-z0-9-]+\.)?amazon\.(co\.uk|de|fr|it|es|in|nl|ru)/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ), |
107 '#https?://([a-z0-9-]+\.)?amazon\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ), |
109 '#https?://([a-z0-9-]+\.)?amazon\.(co\.jp|com\.au)/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ), |
108 '#https?://(www\.)?a\.co/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), |
110 '#https?://([a-z0-9-]+\.)?amazon\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ), |
109 '#https?://(www\.)?amzn\.to/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), |
111 '#https?://(www\.)?a\.co/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), |
110 '#https?://(www\.)?amzn\.eu/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ), |
112 '#https?://(www\.)?amzn\.to/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), |
111 '#https?://(www\.)?amzn\.in/.*#i' => array( 'https://read.amazon.in/kp/api/oembed', true ), |
113 '#https?://(www\.)?amzn\.eu/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ), |
112 '#https?://(www\.)?amzn\.asia/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ), |
114 '#https?://(www\.)?amzn\.in/.*#i' => array( 'https://read.amazon.in/kp/api/oembed', true ), |
113 '#https?://(www\.)?z\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ), |
115 '#https?://(www\.)?amzn\.asia/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ), |
114 '#https?://www\.someecards\.com/.+-cards/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), |
116 '#https?://(www\.)?z\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ), |
115 '#https?://www\.someecards\.com/usercards/viewcard/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), |
117 '#https?://www\.someecards\.com/.+-cards/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), |
116 '#https?://some\.ly\/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), |
118 '#https?://www\.someecards\.com/usercards/viewcard/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), |
|
119 '#https?://some\.ly\/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), |
|
120 ); |
117 ); |
121 |
118 |
122 if ( ! empty( self::$early_providers['add'] ) ) { |
119 if ( ! empty( self::$early_providers['add'] ) ) { |
123 foreach ( self::$early_providers['add'] as $format => $data ) { |
120 foreach ( self::$early_providers['add'] as $format => $data ) { |
124 $providers[ $format ] = $data; |
121 $providers[ $format ] = $data; |
140 * iframes. The providers in this list are whitelisted, meaning they are trusted and allowed to |
137 * iframes. The providers in this list are whitelisted, meaning they are trusted and allowed to |
141 * embed any content, such as iframes, videos, JavaScript, and arbitrary HTML. |
138 * embed any content, such as iframes, videos, JavaScript, and arbitrary HTML. |
142 * |
139 * |
143 * Supported providers: |
140 * Supported providers: |
144 * |
141 * |
145 * | Provider | Flavor | Supports HTTPS | Since | |
142 * | Provider | Flavor | Supports HTTPS | Since | |
146 * | ------------ | --------------------------------- | :------------: | ------- | |
143 * | ------------ | ----------------------------------------- | :------------: | ------- | |
147 * | Dailymotion | dailymotion.com | Yes | 2.9.0 | |
144 * | Dailymotion | dailymotion.com | Yes | 2.9.0 | |
148 * | Flickr | flickr.com | Yes | 2.9.0 | |
145 * | Flickr | flickr.com | Yes | 2.9.0 | |
149 * | Hulu | hulu.com | Yes | 2.9.0 | |
146 * | Hulu | hulu.com | Yes | 2.9.0 | |
150 * | Photobucket | photobucket.com | No | 2.9.0 | |
147 * | Scribd | scribd.com | Yes | 2.9.0 | |
151 * | Scribd | scribd.com | Yes | 2.9.0 | |
148 * | Vimeo | vimeo.com | Yes | 2.9.0 | |
152 * | Vimeo | vimeo.com | Yes | 2.9.0 | |
149 * | WordPress.tv | wordpress.tv | Yes | 2.9.0 | |
153 * | WordPress.tv | wordpress.tv | Yes | 2.9.0 | |
150 * | YouTube | youtube.com/watch | Yes | 2.9.0 | |
154 * | YouTube | youtube.com/watch | Yes | 2.9.0 | |
151 * | Crowdsignal | polldaddy.com | Yes | 3.0.0 | |
155 * | Funny or Die | funnyordie.com | Yes | 3.0.0 | |
152 * | SmugMug | smugmug.com | Yes | 3.0.0 | |
156 * | Polldaddy | polldaddy.com | Yes | 3.0.0 | |
153 * | YouTube | youtu.be | Yes | 3.0.0 | |
157 * | SmugMug | smugmug.com | Yes | 3.0.0 | |
154 * | Twitter | twitter.com | Yes | 3.4.0 | |
158 * | YouTube | youtu.be | Yes | 3.0.0 | |
155 * | Instagram | instagram.com | Yes | 3.5.0 | |
159 * | Twitter | twitter.com | Yes | 3.4.0 | |
156 * | Instagram | instagr.am | Yes | 3.5.0 | |
160 * | Instagram | instagram.com | Yes | 3.5.0 | |
157 * | Slideshare | slideshare.net | Yes | 3.5.0 | |
161 * | Instagram | instagr.am | Yes | 3.5.0 | |
158 * | SoundCloud | soundcloud.com | Yes | 3.5.0 | |
162 * | Slideshare | slideshare.net | Yes | 3.5.0 | |
159 * | Dailymotion | dai.ly | Yes | 3.6.0 | |
163 * | SoundCloud | soundcloud.com | Yes | 3.5.0 | |
160 * | Flickr | flic.kr | Yes | 3.6.0 | |
164 * | Dailymotion | dai.ly | Yes | 3.6.0 | |
161 * | Spotify | spotify.com | Yes | 3.6.0 | |
165 * | Flickr | flic.kr | Yes | 3.6.0 | |
162 * | Imgur | imgur.com | Yes | 3.9.0 | |
166 * | Spotify | spotify.com | Yes | 3.6.0 | |
163 * | Meetup.com | meetup.com | Yes | 3.9.0 | |
167 * | Imgur | imgur.com | Yes | 3.9.0 | |
164 * | Meetup.com | meetu.ps | Yes | 3.9.0 | |
168 * | Meetup.com | meetup.com | Yes | 3.9.0 | |
165 * | Animoto | animoto.com | Yes | 4.0.0 | |
169 * | Meetup.com | meetu.ps | Yes | 3.9.0 | |
166 * | Animoto | video214.com | Yes | 4.0.0 | |
170 * | Animoto | animoto.com | Yes | 4.0.0 | |
167 * | CollegeHumor | collegehumor.com | Yes | 4.0.0 | |
171 * | Animoto | video214.com | Yes | 4.0.0 | |
168 * | Issuu | issuu.com | Yes | 4.0.0 | |
172 * | CollegeHumor | collegehumor.com | Yes | 4.0.0 | |
169 * | Mixcloud | mixcloud.com | Yes | 4.0.0 | |
173 * | Issuu | issuu.com | Yes | 4.0.0 | |
170 * | Crowdsignal | poll.fm | Yes | 4.0.0 | |
174 * | Mixcloud | mixcloud.com | Yes | 4.0.0 | |
171 * | TED | ted.com | Yes | 4.0.0 | |
175 * | Polldaddy | poll.fm | Yes | 4.0.0 | |
172 * | YouTube | youtube.com/playlist | Yes | 4.0.0 | |
176 * | TED | ted.com | Yes | 4.0.0 | |
173 * | Tumblr | tumblr.com | Yes | 4.2.0 | |
177 * | YouTube | youtube.com/playlist | Yes | 4.0.0 | |
174 * | Kickstarter | kickstarter.com | Yes | 4.2.0 | |
178 * | Tumblr | tumblr.com | Yes | 4.2.0 | |
175 * | Kickstarter | kck.st | Yes | 4.2.0 | |
179 * | Kickstarter | kickstarter.com | Yes | 4.2.0 | |
176 * | Cloudup | cloudup.com | Yes | 4.3.0 | |
180 * | Kickstarter | kck.st | Yes | 4.2.0 | |
177 * | ReverbNation | reverbnation.com | Yes | 4.4.0 | |
181 * | Cloudup | cloudup.com | Yes | 4.3.0 | |
178 * | VideoPress | videopress.com | Yes | 4.4.0 | |
182 * | ReverbNation | reverbnation.com | Yes | 4.4.0 | |
179 * | Reddit | reddit.com | Yes | 4.4.0 | |
183 * | VideoPress | videopress.com | Yes | 4.4.0 | |
180 * | Speaker Deck | speakerdeck.com | Yes | 4.4.0 | |
184 * | Reddit | reddit.com | Yes | 4.4.0 | |
181 * | Twitter | twitter.com/timelines | Yes | 4.5.0 | |
185 * | Speaker Deck | speakerdeck.com | Yes | 4.4.0 | |
182 * | Twitter | twitter.com/moments | Yes | 4.5.0 | |
186 * | Twitter | twitter.com/timelines | Yes | 4.5.0 | |
183 * | Facebook | facebook.com | Yes | 4.7.0 | |
187 * | Twitter | twitter.com/moments | Yes | 4.5.0 | |
184 * | Twitter | twitter.com/user | Yes | 4.7.0 | |
188 * | Facebook | facebook.com | Yes | 4.7.0 | |
185 * | Twitter | twitter.com/likes | Yes | 4.7.0 | |
189 * | Twitter | twitter.com/user | Yes | 4.7.0 | |
186 * | Twitter | twitter.com/lists | Yes | 4.7.0 | |
190 * | Twitter | twitter.com/likes | Yes | 4.7.0 | |
187 * | Screencast | screencast.com | Yes | 4.8.0 | |
191 * | Twitter | twitter.com/lists | Yes | 4.7.0 | |
188 * | Amazon | amazon.com (com.mx, com.br, ca) | Yes | 4.9.0 | |
192 * | Screencast | screencast.com | Yes | 4.8.0 | |
189 * | Amazon | amazon.de (fr, it, es, in, nl, ru, co.uk) | Yes | 4.9.0 | |
193 * | Amazon | amazon.com|com.mx|com.br|ca | Yes | 4.9.0 | |
190 * | Amazon | amazon.co.jp (com.au) | Yes | 4.9.0 | |
194 * | Amazon | amazon.de|fr|it|es|in|nl|ru|co.uk | Yes | 4.9.0 | |
191 * | Amazon | amazon.cn | Yes | 4.9.0 | |
195 * | Amazon | amazon.co.jp|com.au | Yes | 4.9.0 | |
192 * | Amazon | a.co | Yes | 4.9.0 | |
196 * | Amazon | amazon.cn | Yes | 4.9.0 | |
193 * | Amazon | amzn.to (eu, in, asia) | Yes | 4.9.0 | |
197 * | Amazon | a.co | Yes | 4.9.0 | |
194 * | Amazon | z.cn | Yes | 4.9.0 | |
198 * | Amazon | amzn.to|eu|in|asia | Yes | 4.9.0 | |
195 * | Someecards | someecards.com | Yes | 4.9.0 | |
199 * | Amazon | z.cn | Yes | 4.9.0 | |
196 * | Someecards | some.ly | Yes | 4.9.0 | |
200 * | Someecards | someecards.com | Yes | 4.9.0 | |
197 * | Crowdsignal | survey.fm | Yes | 5.1.0 | |
201 * | Someecards | some.ly | Yes | 4.9.0 | |
198 * | Instagram TV | instagram.com | Yes | 5.1.0 | |
199 * | Instagram TV | instagr.am | Yes | 5.1.0 | |
|
202 * |
200 * |
203 * No longer supported providers: |
201 * No longer supported providers: |
204 * |
202 * |
205 * | Provider | Flavor | Supports HTTPS | Since | Removed | |
203 * | Provider | Flavor | Supports HTTPS | Since | Removed | |
206 * | ------------ | -------------------- | :------------: | --------- | --------- | |
204 * | ------------ | -------------------- | :------------: | --------- | --------- | |
209 * | Revision3 | revision3.com | No | 2.9.0 | 4.2.0 | |
207 * | Revision3 | revision3.com | No | 2.9.0 | 4.2.0 | |
210 * | Blip | blip.tv | No | 2.9.0 | 4.4.0 | |
208 * | Blip | blip.tv | No | 2.9.0 | 4.4.0 | |
211 * | Rdio | rdio.com | Yes | 3.6.0 | 4.4.1 | |
209 * | Rdio | rdio.com | Yes | 3.6.0 | 4.4.1 | |
212 * | Rdio | rd.io | Yes | 3.6.0 | 4.4.1 | |
210 * | Rdio | rd.io | Yes | 3.6.0 | 4.4.1 | |
213 * | Vine | vine.co | Yes | 4.1.0 | 4.9.0 | |
211 * | Vine | vine.co | Yes | 4.1.0 | 4.9.0 | |
212 * | Photobucket | photobucket.com | No | 2.9.0 | 5.1.0 | |
|
213 * | Funny or Die | funnyordie.com | Yes | 3.0.0 | 5.1.0 | |
|
214 * |
214 * |
215 * @see wp_oembed_add_provider() |
215 * @see wp_oembed_add_provider() |
216 * |
216 * |
217 * @since 2.9.0 |
217 * @since 2.9.0 |
218 * |
218 * |
219 * @param array $providers An array of popular oEmbed providers. |
219 * @param array[] $providers An array of arrays containing data about popular oEmbed providers. |
220 */ |
220 */ |
221 $this->providers = apply_filters( 'oembed_providers', $providers ); |
221 $this->providers = apply_filters( 'oembed_providers', $providers ); |
222 |
222 |
223 // Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop(). |
223 // Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop(). |
224 add_filter( 'oembed_dataparse', array($this, '_strip_newlines'), 10, 3 ); |
224 add_filter( 'oembed_dataparse', array( $this, '_strip_newlines' ), 10, 3 ); |
225 } |
225 } |
226 |
226 |
227 /** |
227 /** |
228 * Exposes private/protected methods for backward compatibility. |
228 * Exposes private/protected methods for backward compatibility. |
229 * |
229 * |
230 * @since 4.0.0 |
230 * @since 4.0.0 |
231 * |
231 * |
232 * @param callable $name Method to call. |
232 * @param string $name Method to call. |
233 * @param array $arguments Arguments to pass when calling. |
233 * @param array $arguments Arguments to pass when calling. |
234 * @return mixed|bool Return value of the callback, false otherwise. |
234 * @return mixed|bool Return value of the callback, false otherwise. |
235 */ |
235 */ |
236 public function __call( $name, $arguments ) { |
236 public function __call( $name, $arguments ) { |
237 if ( in_array( $name, $this->compat_methods ) ) { |
237 if ( in_array( $name, $this->compat_methods ) ) { |
254 public function get_provider( $url, $args = '' ) { |
254 public function get_provider( $url, $args = '' ) { |
255 $args = wp_parse_args( $args ); |
255 $args = wp_parse_args( $args ); |
256 |
256 |
257 $provider = false; |
257 $provider = false; |
258 |
258 |
259 if ( !isset($args['discover']) ) |
259 if ( ! isset( $args['discover'] ) ) { |
260 $args['discover'] = true; |
260 $args['discover'] = true; |
261 } |
|
261 |
262 |
262 foreach ( $this->providers as $matchmask => $data ) { |
263 foreach ( $this->providers as $matchmask => $data ) { |
263 list( $providerurl, $regex ) = $data; |
264 list( $providerurl, $regex ) = $data; |
264 |
265 |
265 // Turn the asterisk-type provider URLs into regex |
266 // Turn the asterisk-type provider URLs into regex |
266 if ( !$regex ) { |
267 if ( ! $regex ) { |
267 $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i'; |
268 $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i'; |
268 $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask ); |
269 $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask ); |
269 } |
270 } |
270 |
271 |
271 if ( preg_match( $matchmask, $url ) ) { |
272 if ( preg_match( $matchmask, $url ) ) { |
272 $provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML |
273 $provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML |
273 break; |
274 break; |
274 } |
275 } |
275 } |
276 } |
276 |
277 |
277 if ( !$provider && $args['discover'] ) |
278 if ( ! $provider && $args['discover'] ) { |
278 $provider = $this->discover( $url ); |
279 $provider = $this->discover( $url ); |
280 } |
|
279 |
281 |
280 return $provider; |
282 return $provider; |
281 } |
283 } |
282 |
284 |
283 /** |
285 /** |
286 * The provider is added just-in-time when wp_oembed_add_provider() is called before |
288 * The provider is added just-in-time when wp_oembed_add_provider() is called before |
287 * the {@see 'plugins_loaded'} hook. |
289 * the {@see 'plugins_loaded'} hook. |
288 * |
290 * |
289 * The just-in-time addition is for the benefit of the {@see 'oembed_providers'} filter. |
291 * The just-in-time addition is for the benefit of the {@see 'oembed_providers'} filter. |
290 * |
292 * |
291 * @static |
|
292 * @since 4.0.0 |
293 * @since 4.0.0 |
293 * |
294 * |
294 * @see wp_oembed_add_provider() |
295 * @see wp_oembed_add_provider() |
295 * |
296 * |
296 * @param string $format Format of URL that this provider can handle. You can use |
297 * @param string $format Format of URL that this provider can handle. You can use |
314 * the {@see 'plugins_loaded'} hook. |
315 * the {@see 'plugins_loaded'} hook. |
315 * |
316 * |
316 * The just-in-time removal is for the benefit of the {@see 'oembed_providers'} filter. |
317 * The just-in-time removal is for the benefit of the {@see 'oembed_providers'} filter. |
317 * |
318 * |
318 * @since 4.0.0 |
319 * @since 4.0.0 |
319 * @static |
|
320 * |
320 * |
321 * @see wp_oembed_remove_provider() |
321 * @see wp_oembed_remove_provider() |
322 * |
322 * |
323 * @param string $format The format of URL that this provider can handle. You can use |
323 * @param string $format The format of URL that this provider can handle. You can use |
324 * asterisks as wildcards. |
324 * asterisks as wildcards. |
403 /** |
403 /** |
404 * Filters the HTML returned by the oEmbed provider. |
404 * Filters the HTML returned by the oEmbed provider. |
405 * |
405 * |
406 * @since 2.9.0 |
406 * @since 2.9.0 |
407 * |
407 * |
408 * @param string $data The returned oEmbed HTML. |
408 * @param string|false $data The returned oEmbed HTML (false if unsafe). |
409 * @param string $url URL of the content to be embedded. |
409 * @param string $url URL of the content to be embedded. |
410 * @param array $args Optional arguments, usually passed from a shortcode. |
410 * @param array $args Optional arguments, usually passed from a shortcode. |
411 */ |
411 */ |
412 return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args ); |
412 return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args ); |
413 } |
413 } |
414 |
414 |
415 /** |
415 /** |
420 * @param string $url The URL that should be inspected for discovery `<link>` tags. |
420 * @param string $url The URL that should be inspected for discovery `<link>` tags. |
421 * @return false|string False on failure, otherwise the oEmbed provider URL. |
421 * @return false|string False on failure, otherwise the oEmbed provider URL. |
422 */ |
422 */ |
423 public function discover( $url ) { |
423 public function discover( $url ) { |
424 $providers = array(); |
424 $providers = array(); |
425 $args = array( |
425 $args = array( |
426 'limit_response_size' => 153600, // 150 KB |
426 'limit_response_size' => 153600, // 150 KB |
427 ); |
427 ); |
428 |
428 |
429 /** |
429 /** |
430 * Filters oEmbed remote get arguments. |
430 * Filters oEmbed remote get arguments. |
445 /** |
445 /** |
446 * Filters the link types that contain oEmbed provider URLs. |
446 * Filters the link types that contain oEmbed provider URLs. |
447 * |
447 * |
448 * @since 2.9.0 |
448 * @since 2.9.0 |
449 * |
449 * |
450 * @param array $format Array of oEmbed link types. Accepts 'application/json+oembed', |
450 * @param string[] $format Array of oEmbed link types. Accepts 'application/json+oembed', |
451 * 'text/xml+oembed', and 'application/xml+oembed' (incorrect, |
451 * 'text/xml+oembed', and 'application/xml+oembed' (incorrect, |
452 * used by at least Vimeo). |
452 * used by at least Vimeo). |
453 */ |
453 */ |
454 $linktypes = apply_filters( 'oembed_linktypes', array( |
454 $linktypes = apply_filters( |
455 'application/json+oembed' => 'json', |
455 'oembed_linktypes', |
456 'text/xml+oembed' => 'xml', |
456 array( |
457 'application/xml+oembed' => 'xml', |
457 'application/json+oembed' => 'json', |
458 ) ); |
458 'text/xml+oembed' => 'xml', |
459 'application/xml+oembed' => 'xml', |
|
460 ) |
|
461 ); |
|
459 |
462 |
460 // Strip <body> |
463 // Strip <body> |
461 if ( $html_head_end = stripos( $html, '</head>' ) ) { |
464 if ( $html_head_end = stripos( $html, '</head>' ) ) { |
462 $html = substr( $html, 0, $html_head_end ); |
465 $html = substr( $html, 0, $html_head_end ); |
463 } |
466 } |
464 |
467 |
465 // Do a quick check |
468 // Do a quick check |
466 $tagfound = false; |
469 $tagfound = false; |
467 foreach ( $linktypes as $linktype => $format ) { |
470 foreach ( $linktypes as $linktype => $format ) { |
468 if ( stripos($html, $linktype) ) { |
471 if ( stripos( $html, $linktype ) ) { |
469 $tagfound = true; |
472 $tagfound = true; |
470 break; |
473 break; |
471 } |
474 } |
472 } |
475 } |
473 |
476 |
474 if ( $tagfound && preg_match_all( '#<link([^<>]+)/?>#iU', $html, $links ) ) { |
477 if ( $tagfound && preg_match_all( '#<link([^<>]+)/?>#iU', $html, $links ) ) { |
475 foreach ( $links[1] as $link ) { |
478 foreach ( $links[1] as $link ) { |
476 $atts = shortcode_parse_atts( $link ); |
479 $atts = shortcode_parse_atts( $link ); |
477 |
480 |
478 if ( !empty($atts['type']) && !empty($linktypes[$atts['type']]) && !empty($atts['href']) ) { |
481 if ( ! empty( $atts['type'] ) && ! empty( $linktypes[ $atts['type'] ] ) && ! empty( $atts['href'] ) ) { |
479 $providers[$linktypes[$atts['type']]] = htmlspecialchars_decode( $atts['href'] ); |
482 $providers[ $linktypes[ $atts['type'] ] ] = htmlspecialchars_decode( $atts['href'] ); |
480 |
483 |
481 // Stop here if it's JSON (that's all we need) |
484 // Stop here if it's JSON (that's all we need) |
482 if ( 'json' == $linktypes[$atts['type']] ) |
485 if ( 'json' == $linktypes[ $atts['type'] ] ) { |
483 break; |
486 break; |
487 } |
|
484 } |
488 } |
485 } |
489 } |
486 } |
490 } |
487 } |
491 } |
488 |
492 |
489 // JSON is preferred to XML |
493 // JSON is preferred to XML |
490 if ( !empty($providers['json']) ) |
494 if ( ! empty( $providers['json'] ) ) { |
491 return $providers['json']; |
495 return $providers['json']; |
492 elseif ( !empty($providers['xml']) ) |
496 } elseif ( ! empty( $providers['xml'] ) ) { |
493 return $providers['xml']; |
497 return $providers['xml']; |
494 else |
498 } else { |
495 return false; |
499 return false; |
500 } |
|
496 } |
501 } |
497 |
502 |
498 /** |
503 /** |
499 * Connects to a oEmbed provider and returns the result. |
504 * Connects to a oEmbed provider and returns the result. |
500 * |
505 * |
508 public function fetch( $provider, $url, $args = '' ) { |
513 public function fetch( $provider, $url, $args = '' ) { |
509 $args = wp_parse_args( $args, wp_embed_defaults( $url ) ); |
514 $args = wp_parse_args( $args, wp_embed_defaults( $url ) ); |
510 |
515 |
511 $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider ); |
516 $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider ); |
512 $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider ); |
517 $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider ); |
513 $provider = add_query_arg( 'url', urlencode($url), $provider ); |
518 $provider = add_query_arg( 'url', urlencode( $url ), $provider ); |
514 $provider = add_query_arg( 'dnt', 1, $provider ); |
519 $provider = add_query_arg( 'dnt', 1, $provider ); |
515 |
520 |
516 /** |
521 /** |
517 * Filters the oEmbed URL to be fetched. |
522 * Filters the oEmbed URL to be fetched. |
518 * |
523 * |
525 */ |
530 */ |
526 $provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args ); |
531 $provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args ); |
527 |
532 |
528 foreach ( array( 'json', 'xml' ) as $format ) { |
533 foreach ( array( 'json', 'xml' ) as $format ) { |
529 $result = $this->_fetch_with_format( $provider, $format ); |
534 $result = $this->_fetch_with_format( $provider, $format ); |
530 if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() ) |
535 if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() ) { |
531 continue; |
536 continue; |
537 } |
|
532 return ( $result && ! is_wp_error( $result ) ) ? $result : false; |
538 return ( $result && ! is_wp_error( $result ) ) ? $result : false; |
533 } |
539 } |
534 return false; |
540 return false; |
535 } |
541 } |
536 |
542 |
548 |
554 |
549 /** This filter is documented in wp-includes/class-oembed.php */ |
555 /** This filter is documented in wp-includes/class-oembed.php */ |
550 $args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args ); |
556 $args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args ); |
551 |
557 |
552 $response = wp_safe_remote_get( $provider_url_with_args, $args ); |
558 $response = wp_safe_remote_get( $provider_url_with_args, $args ); |
553 if ( 501 == wp_remote_retrieve_response_code( $response ) ) |
559 if ( 501 == wp_remote_retrieve_response_code( $response ) ) { |
554 return new WP_Error( 'not-implemented' ); |
560 return new WP_Error( 'not-implemented' ); |
555 if ( ! $body = wp_remote_retrieve_body( $response ) ) |
561 } |
556 return false; |
562 if ( ! $body = wp_remote_retrieve_body( $response ) ) { |
563 return false; |
|
564 } |
|
557 $parse_method = "_parse_$format"; |
565 $parse_method = "_parse_$format"; |
558 return $this->$parse_method( $body ); |
566 return $this->$parse_method( $body ); |
559 } |
567 } |
560 |
568 |
561 /** |
569 /** |
578 * |
586 * |
579 * @param string $response_body |
587 * @param string $response_body |
580 * @return object|false |
588 * @return object|false |
581 */ |
589 */ |
582 private function _parse_xml( $response_body ) { |
590 private function _parse_xml( $response_body ) { |
583 if ( ! function_exists( 'libxml_disable_entity_loader' ) ) |
591 if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { |
584 return false; |
592 return false; |
593 } |
|
585 |
594 |
586 $loader = libxml_disable_entity_loader( true ); |
595 $loader = libxml_disable_entity_loader( true ); |
587 $errors = libxml_use_internal_errors( true ); |
596 $errors = libxml_use_internal_errors( true ); |
588 |
597 |
589 $return = $this->_parse_xml_body( $response_body ); |
598 $return = $this->_parse_xml_body( $response_body ); |
601 * |
610 * |
602 * @param string $response_body |
611 * @param string $response_body |
603 * @return stdClass|false |
612 * @return stdClass|false |
604 */ |
613 */ |
605 private function _parse_xml_body( $response_body ) { |
614 private function _parse_xml_body( $response_body ) { |
606 if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) ) |
615 if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) ) { |
607 return false; |
616 return false; |
608 |
617 } |
609 $dom = new DOMDocument; |
618 |
619 $dom = new DOMDocument; |
|
610 $success = $dom->loadXML( $response_body ); |
620 $success = $dom->loadXML( $response_body ); |
611 if ( ! $success ) |
621 if ( ! $success ) { |
612 return false; |
622 return false; |
613 |
623 } |
614 if ( isset( $dom->doctype ) ) |
624 |
615 return false; |
625 if ( isset( $dom->doctype ) ) { |
626 return false; |
|
627 } |
|
616 |
628 |
617 foreach ( $dom->childNodes as $child ) { |
629 foreach ( $dom->childNodes as $child ) { |
618 if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) |
630 if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) { |
619 return false; |
631 return false; |
632 } |
|
620 } |
633 } |
621 |
634 |
622 $xml = simplexml_import_dom( $dom ); |
635 $xml = simplexml_import_dom( $dom ); |
623 if ( ! $xml ) |
636 if ( ! $xml ) { |
624 return false; |
637 return false; |
638 } |
|
625 |
639 |
626 $return = new stdClass; |
640 $return = new stdClass; |
627 foreach ( $xml as $key => $value ) { |
641 foreach ( $xml as $key => $value ) { |
628 $return->$key = (string) $value; |
642 $return->$key = (string) $value; |
629 } |
643 } |
639 * @param object $data A data object result from an oEmbed provider. |
653 * @param object $data A data object result from an oEmbed provider. |
640 * @param string $url The URL to the content that is desired to be embedded. |
654 * @param string $url The URL to the content that is desired to be embedded. |
641 * @return false|string False on error, otherwise the HTML needed to embed. |
655 * @return false|string False on error, otherwise the HTML needed to embed. |
642 */ |
656 */ |
643 public function data2html( $data, $url ) { |
657 public function data2html( $data, $url ) { |
644 if ( ! is_object( $data ) || empty( $data->type ) ) |
658 if ( ! is_object( $data ) || empty( $data->type ) ) { |
645 return false; |
659 return false; |
660 } |
|
646 |
661 |
647 $return = false; |
662 $return = false; |
648 |
663 |
649 switch ( $data->type ) { |
664 switch ( $data->type ) { |
650 case 'photo': |
665 case 'photo': |
651 if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) ) |
666 if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) ) { |
652 break; |
667 break; |
653 if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) ) |
668 } |
669 if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) ) { |
|
654 break; |
670 break; |
655 |
671 } |
656 $title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : ''; |
672 |
657 $return = '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $data->url ) . '" alt="' . esc_attr($title) . '" width="' . esc_attr($data->width) . '" height="' . esc_attr($data->height) . '" /></a>'; |
673 $title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : ''; |
674 $return = '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $data->url ) . '" alt="' . esc_attr( $title ) . '" width="' . esc_attr( $data->width ) . '" height="' . esc_attr( $data->height ) . '" /></a>'; |
|
658 break; |
675 break; |
659 |
676 |
660 case 'video': |
677 case 'video': |
661 case 'rich': |
678 case 'rich': |
662 if ( ! empty( $data->html ) && is_string( $data->html ) ) |
679 if ( ! empty( $data->html ) && is_string( $data->html ) ) { |
663 $return = $data->html; |
680 $return = $data->html; |
681 } |
|
664 break; |
682 break; |
665 |
683 |
666 case 'link': |
684 case 'link': |
667 if ( ! empty( $data->title ) && is_string( $data->title ) ) |
685 if ( ! empty( $data->title ) && is_string( $data->title ) ) { |
668 $return = '<a href="' . esc_url( $url ) . '">' . esc_html( $data->title ) . '</a>'; |
686 $return = '<a href="' . esc_url( $url ) . '">' . esc_html( $data->title ) . '</a>'; |
687 } |
|
669 break; |
688 break; |
670 |
689 |
671 default: |
690 default: |
672 $return = false; |
691 $return = false; |
673 } |
692 } |
700 public function _strip_newlines( $html, $data, $url ) { |
719 public function _strip_newlines( $html, $data, $url ) { |
701 if ( false === strpos( $html, "\n" ) ) { |
720 if ( false === strpos( $html, "\n" ) ) { |
702 return $html; |
721 return $html; |
703 } |
722 } |
704 |
723 |
705 $count = 1; |
724 $count = 1; |
706 $found = array(); |
725 $found = array(); |
707 $token = '__PRE__'; |
726 $token = '__PRE__'; |
708 $search = array( "\t", "\n", "\r", ' ' ); |
727 $search = array( "\t", "\n", "\r", ' ' ); |
709 $replace = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' ); |
728 $replace = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' ); |
710 $tokenized = str_replace( $search, $replace, $html ); |
729 $tokenized = str_replace( $search, $replace, $html ); |
711 |
730 |
712 preg_match_all( '#(<pre[^>]*>.+?</pre>)#i', $tokenized, $matches, PREG_SET_ORDER ); |
731 preg_match_all( '#(<pre[^>]*>.+?</pre>)#i', $tokenized, $matches, PREG_SET_ORDER ); |
713 foreach ( $matches as $i => $match ) { |
732 foreach ( $matches as $i => $match ) { |
714 $tag_html = str_replace( $replace, $search, $match[0] ); |
733 $tag_html = str_replace( $replace, $search, $match[0] ); |
715 $tag_token = $token . $i; |
734 $tag_token = $token . $i; |
716 |
735 |
717 $found[ $tag_token ] = $tag_html; |
736 $found[ $tag_token ] = $tag_html; |
718 $html = str_replace( $tag_html, $tag_token, $html, $count ); |
737 $html = str_replace( $tag_html, $tag_token, $html, $count ); |
719 } |
738 } |
720 |
739 |
721 $replaced = str_replace( $replace, $search, $html ); |
740 $replaced = str_replace( $replace, $search, $html ); |
722 $stripped = str_replace( array( "\r\n", "\n" ), '', $replaced ); |
741 $stripped = str_replace( array( "\r\n", "\n" ), '', $replaced ); |
723 $pre = array_values( $found ); |
742 $pre = array_values( $found ); |
724 $tokens = array_keys( $found ); |
743 $tokens = array_keys( $found ); |
725 |
744 |
726 return str_replace( $tokens, $pre, $stripped ); |
745 return str_replace( $tokens, $pre, $stripped ); |
727 } |
746 } |
728 } |
747 } |