| 1 | <?php |
| 2 | |
| 3 | class Tests_oEmbed extends WP_UnitTestCase { |
| 4 | protected static $oembed; |
| 5 | protected static $provider_map = array( |
| 6 | 'youtube' => '#https?://((m|www)\.)?youtube\.com/watch.*#i', |
| 7 | 'youtube-playlist' => '#https?://((m|www)\.)?youtube\.com/playlist.*#i', |
| 8 | 'youtube-shorturl' => '#https?://youtu\.be/.*#i', |
| 9 | 'vimeo' => '#https?://(.+\.)?vimeo\.com/.*#i', |
| 10 | 'dailymotion' => '#https?://(www\.)?dailymotion\.com/.*#i', |
| 11 | 'dailymotion-shorturl' => '#https?://dai.ly/.*#i', |
| 12 | 'flickr' => '#https?://(www\.)?flickr\.com/.*#i', |
| 13 | 'flickr-shorturl' => '#https?://flic\.kr/.*#i', |
| 14 | 'smugmug' => '#https?://(.+\.)?smugmug\.com/.*#i', |
| 15 | 'hulu' => '#https?://(www\.)?hulu\.com/watch/.*#i', |
| 16 | 'photobucket-album' => 'http://i*.photobucket.com/albums/*', |
| 17 | 'photobucket-group' => 'http://gi*.photobucket.com/groups/*', |
| 18 | 'scribd' => '#https?://(www\.)?scribd\.com/doc/.*#i', |
| 19 | 'wordpress-tv' => '#https?://wordpress.tv/.*#i', |
| 20 | 'polldaddy' => '#https?://(.+\.)?polldaddy\.com/.*#i', |
| 21 | 'polldaddy-shorturl' => '#https?://poll\.fm/.*#i', |
| 22 | 'funnyordie' => '#https?://(www\.)?funnyordie\.com/videos/.*#i', |
| 23 | 'twitter' => '#https?://(www\.)?twitter\.com/.+?/status(es)?/.*#i', |
| 24 | 'twitter-timeline' => '#https?://(www\.)?twitter\.com/.+?/timelines/.*#i', |
| 25 | 'twitter-moment' => '#https?://(www\.)?twitter\.com/i/moments/.*#i', |
| 26 | 'vine' => '#https?://vine.co/v/.*#i', |
| 27 | 'soundcloud' => '#https?://(www\.)?soundcloud\.com/.*#i', |
| 28 | 'slideshare' => '#https?://(.+?\.)?slideshare\.net/.*#i', |
| 29 | 'instagram' => '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i', |
| 30 | 'spotify' => '#https?://(open|play)\.spotify\.com/.*#i', |
| 31 | 'imgur' => '#https?://(.+\.)?imgur\.com/.*#i', |
| 32 | 'meetup' => '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i', |
| 33 | 'issuu' => '#https?://(www\.)?issuu\.com/.+/docs/.+#i', |
| 34 | 'collegehumor' => '#https?://(www\.)?collegehumor\.com/video/.*#i', |
| 35 | 'mixcloud' => '#https?://(www\.)?mixcloud\.com/.*#i', |
| 36 | 'ted' => '#https?://(www\.|embed\.)?ted\.com/talks/.*#i', |
| 37 | 'animoto' => '#https?://(www\.)?(animoto|video214)\.com/play/.*#i', |
| 38 | 'tumblr' => '#https?://(.+)\.tumblr\.com/post/.*#i', |
| 39 | 'kickstarter' => '#https?://(www\.)?kickstarter\.com/projects/.*#i', |
| 40 | 'kickstarter-shorturl' => '#https?://kck\.st/.*#i', |
| 41 | 'cloudup' => '#https?://cloudup\.com/.*#i', |
| 42 | 'reverbnation' => '#https?://(www\.)?reverbnation\.com/.*#i', |
| 43 | 'videopress' => '#https?://videopress.com/v/.*#', |
| 44 | 'reddit-comments' => '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i', |
| 45 | 'speakerdeck' => '#https?://(www\.)?speakerdeck\.com/.*#i', |
| 46 | 'facebook-post' => '#https?://www\.facebook\.com/.*/posts/.*#i', |
| 47 | 'facebook-photo' => '#https?://www\.facebook\.com/photo(s/|\.php).*#i', |
| 48 | 'facebook-permalink' => '#https?://www\.facebook\.com/permalink\.php.*#i', |
| 49 | 'facebook-media' => '#https?://www\.facebook\.com/media/.*#i', |
| 50 | 'facebook-notes' => '#https?://www\.facebook\.com/notes/.*#i', |
| 51 | 'facebook-video' => '#https?://www\.facebook\.com/.*/videos/.*#i', |
| 52 | 'facebook-videophp' => '#https?://www\.facebook\.com/video\.php.*#i', |
| 53 | // I can't find URLs in this format |
| 54 | //'facebook-activity' => '#https?://www\.facebook\.com/.*/activity/.*#i', |
| 55 | // Questions has been RIP since 2012, URLs (if you can find them) should still work |
| 56 | //'facebook-questions' => '#https?://www\.facebook\.com/questions/.*#i', |
| 57 | ); |
| 58 | |
| 59 | /** |
| 60 | * An HTTP API response. |
| 61 | * |
| 62 | * @var array |
| 63 | */ |
| 64 | protected $http_response = array(); |
| 65 | |
| 66 | public static function wpSetUpBeforeClass() { |
| 67 | self::$oembed = _wp_oembed_get_object(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Test the tests |
| 72 | * |
| 73 | * @group external-oembed |
| 74 | * @ticket 28507 |
| 75 | * @ticket 32360 |
| 76 | * |
| 77 | * @dataProvider oEmbedProviderData |
| 78 | */ |
| 79 | public function testOembedTestURLsResolve( $match, array $urls, $supports_https ) { |
| 80 | |
| 81 | if ( empty( $urls ) ) { |
| 82 | $this->markTestIncomplete(); |
| 83 | } |
| 84 | |
| 85 | foreach ( $urls as $url ) { |
| 86 | |
| 87 | $msg = sprintf( 'Test URL: %s', $url ); |
| 88 | |
| 89 | $r = wp_remote_head( $url, array( |
| 90 | 'redirection' => 3, |
| 91 | ) ); |
| 92 | |
| 93 | if ( is_wp_error( $r ) ) { |
| 94 | $this->fail( sprintf( "%s (%s)\n%s", $r->get_error_message(), $r->get_error_code(), $msg ) ); |
| 95 | } |
| 96 | |
| 97 | $this->assertSame( 200, wp_remote_retrieve_response_code( $r ), $msg ); |
| 98 | |
| 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Test the response from each oEmbed provider |
| 105 | * |
| 106 | * @group external-oembed |
| 107 | * @ticket 32360 |
| 108 | * |
| 109 | * @dataProvider oEmbedProviderData |
| 110 | */ |
| 111 | public function testOembedProviderReturnsExpectedResponse( $match, array $urls, $supports_https ) { |
| 112 | |
| 113 | if ( empty( $urls ) ) { |
| 114 | $this->markTestIncomplete(); |
| 115 | } |
| 116 | |
| 117 | $this->setup_http_hooks(); |
| 118 | |
| 119 | $args = array( |
| 120 | 'width' => 500, |
| 121 | 'height' => 500, |
| 122 | ); |
| 123 | $test_urls = $urls; |
| 124 | |
| 125 | if ( $supports_https ) { |
| 126 | foreach ( $urls as $url ) { |
| 127 | $test_urls[] = set_url_scheme( $url, 'https' ); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | foreach ( $test_urls as $url ) { |
| 132 | |
| 133 | $msg = sprintf( "- Test URL: %s", $url ); |
| 134 | |
| 135 | $provider = self::$oembed->get_provider( $url, array( |
| 136 | 'discover' => false, |
| 137 | ) ); |
| 138 | $this->assertNotFalse( $provider, $msg ); |
| 139 | |
| 140 | $data = self::$oembed->fetch( $provider, $url, $args ); |
| 141 | |
| 142 | $r = $this->http_response; |
| 143 | |
| 144 | $msg .= sprintf( "\n- oEmbed URL: %s", $r['url'] ); |
| 145 | |
| 146 | $scheme = parse_url( $r['url'], PHP_URL_SCHEME ); |
| 147 | $query = parse_url( $r['url'], PHP_URL_QUERY ); |
| 148 | parse_str( $query, $query_vars ); |
| 149 | |
| 150 | // Test request |
| 151 | $this->assertInternalType( 'array', $query_vars, $msg ); |
| 152 | $this->assertArrayHasKey( 'maxheight', $query_vars, $msg ); |
| 153 | $this->assertArrayHasKey( 'maxwidth', $query_vars, $msg ); |
| 154 | $this->assertArrayHasKey( 'url', $query_vars, $msg ); |
| 155 | $this->assertArrayHasKey( 'format', $query_vars, $msg ); |
| 156 | $this->assertTrue( in_array( $query_vars['format'], array( 'json', 'xml' ), true ), $msg ); |
| 157 | $this->assertEquals( $args['width'], $query_vars['maxwidth'], $msg ); |
| 158 | $this->assertEquals( $args['height'], $query_vars['maxheight'], $msg ); |
| 159 | |
| 160 | // `WP_oEmbed::fetch()` only returns boolean false, so we need to hook into the HTTP API to get its error |
| 161 | if ( is_wp_error( $r['response'] ) ) { |
| 162 | $error_message = $r['response']->get_error_message(); |
| 163 | if ( empty( $error_message ) ) { |
| 164 | $error_message = '- no message -'; |
| 165 | } |
| 166 | |
| 167 | $this->fail( sprintf( "%s (%s)\n%s", $error_message, $r['response']->get_error_code(), $msg ) ); |
| 168 | } |
| 169 | |
| 170 | $this->assertSame( 200, wp_remote_retrieve_response_code( $r['response'] ), $msg ); |
| 171 | |
| 172 | // Test response |
| 173 | $this->assertNotFalse( $data, $msg ); |
| 174 | |
| 175 | // Check for required response parameters |
| 176 | $this->assertObjectHasAttribute( 'type', $data, $msg ); |
| 177 | $this->assertObjectHasAttribute( 'version', $data, $msg ); |
| 178 | $this->assertEquals( '1.0', $data->version, $msg ); |
| 179 | |
| 180 | switch ( $data->type ) { |
| 181 | |
| 182 | case 'photo': |
| 183 | |
| 184 | // Check for required response parameters |
| 185 | $this->assertObjectHasAttribute( 'url', $data, $msg ); |
| 186 | $this->assertObjectHasAttribute( 'width', $data, $msg ); |
| 187 | $this->assertObjectHasAttribute( 'height', $data, $msg ); |
| 188 | |
| 189 | // Validate response parameters |
| 190 | $this->assertNotEmpty( $data->url, $msg ); |
| 191 | $this->assertInternalType( 'string', $data->url, $msg ); |
| 192 | |
| 193 | // Validate response URL scheme |
| 194 | if ( 'https' === $scheme ) { |
| 195 | $response_scheme = parse_url( $data->url, PHP_URL_SCHEME ); |
| 196 | if ( ! in_array( $response_scheme, array( null, 'https' ), true ) ) { |
| 197 | $this->fail( sprintf( "Invalid scheme in response URL: %s\n%s", $data->url, $msg ) ); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | break; |
| 202 | |
| 203 | case 'video': |
| 204 | |
| 205 | // Check for required response parameters |
| 206 | $this->assertObjectHasAttribute( 'html', $data, $msg ); |
| 207 | $this->assertObjectHasAttribute( 'width', $data, $msg ); |
| 208 | $this->assertObjectHasAttribute( 'height', $data, $msg ); |
| 209 | |
| 210 | // Validate response parameters |
| 211 | $this->assertNotEmpty( $data->html, $msg ); |
| 212 | $this->assertInternalType( 'string', $data->html, $msg ); |
| 213 | |
| 214 | break; |
| 215 | |
| 216 | case 'rich': |
| 217 | |
| 218 | // Check for required response parameters |
| 219 | $this->assertObjectHasAttribute( 'html', $data, $msg ); |
| 220 | $this->assertObjectHasAttribute( 'width', $data, $msg ); |
| 221 | $this->assertObjectHasAttribute( 'height', $data, $msg ); |
| 222 | |
| 223 | // Validate response parameters |
| 224 | $this->assertNotEmpty( $data->html, $msg ); |
| 225 | $this->assertInternalType( 'string', $data->html, $msg ); |
| 226 | |
| 227 | // Validate response URL schemes |
| 228 | if ( 'https' === $scheme ) { |
| 229 | |
| 230 | if ( preg_match_all( '#src="([^"]+)"#', $data->html, $matches ) ) { |
| 231 | foreach ( $matches[1] as $src ) { |
| 232 | $src_scheme = parse_url( $src, PHP_URL_SCHEME ); |
| 233 | if ( ! in_array( $src_scheme, array( null, 'https' ), true ) ) { |
| 234 | $this->fail( sprintf( "Invalid src scheme in response: %s\n%s", $src, $msg ) ); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | } |
| 240 | |
| 241 | break; |
| 242 | |
| 243 | case 'link': |
| 244 | |
| 245 | // Check for required response parameters |
| 246 | $this->assertObjectHasAttribute( 'title', $data, $msg ); |
| 247 | |
| 248 | // Validate response parameters |
| 249 | $this->assertNotEmpty( $data->title, $msg ); |
| 250 | $this->assertInternalType( 'string', $data->title, $msg ); |
| 251 | |
| 252 | break; |
| 253 | |
| 254 | default: |
| 255 | |
| 256 | $this->fail( sprintf( "Invalid value for the 'type' response parameter\n%s", $msg ) ); |
| 257 | |
| 258 | break; |
| 259 | |
| 260 | } |
| 261 | |
| 262 | if ( ! empty( $data->width ) ) { |
| 263 | |
| 264 | // Validate response parameter |
| 265 | $this->assertTrue( is_numeric( $data->width ), $msg ); |
| 266 | $this->assertLessThanOrEqual( intval( $query_vars['maxwidth'] ), $data->width, $msg ); |
| 267 | |
| 268 | } |
| 269 | |
| 270 | if ( ! empty( $data->height ) ) { |
| 271 | |
| 272 | // Validate response parameter |
| 273 | $this->assertTrue( is_numeric( $data->height ), $msg ); |
| 274 | $this->assertLessThanOrEqual( intval( $query_vars['maxheight'] ), $data->height, $msg ); |
| 275 | |
| 276 | } |
| 277 | |
| 278 | if ( ! empty( $data->thumbnail_url ) ) { |
| 279 | |
| 280 | // Check for required response parameters |
| 281 | $this->assertObjectHasAttribute( 'thumbnail_width', $data, $msg ); |
| 282 | $this->assertObjectHasAttribute( 'thumbnail_height', $data, $msg ); |
| 283 | |
| 284 | } |
| 285 | |
| 286 | if ( ! empty( $data->thumbnail_width ) ) { |
| 287 | |
| 288 | // Check for required response parameters |
| 289 | $this->assertObjectHasAttribute( 'thumbnail_url', $data, $msg ); |
| 290 | |
| 291 | // Validate response parameter |
| 292 | $this->assertTrue( is_numeric( $data->thumbnail_width ), $msg ); |
| 293 | $this->assertLessThanOrEqual( intval( $query_vars['maxwidth'] ), $data->thumbnail_width, $msg ); |
| 294 | |
| 295 | } |
| 296 | |
| 297 | if ( ! empty( $data->thumbnail_height ) ) { |
| 298 | |
| 299 | // Check for required response parameters |
| 300 | $this->assertObjectHasAttribute( 'thumbnail_url', $data, $msg ); |
| 301 | |
| 302 | // Validate response parameter |
| 303 | $this->assertTrue( is_numeric( $data->thumbnail_height ), $msg ); |
| 304 | $this->assertLessThanOrEqual( intval( $query_vars['maxheight'] ), $data->thumbnail_height, $msg ); |
| 305 | |
| 306 | } |
| 307 | |
| 308 | } |
| 309 | |
| 310 | $this->teardown_http_hooks(); |
| 311 | |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Test the response from each oEmbed provider when provided with invalid data |
| 316 | * |
| 317 | * @group external-oembed |
| 318 | * @ticket 32360 |
| 319 | * |
| 320 | * @dataProvider oEmbedProviderData |
| 321 | */ |
| 322 | public function testOembedProviderHandlesInvalidData( $match, array $urls, $supports_https ) { |
| 323 | |
| 324 | if ( empty( $urls ) ) { |
| 325 | $this->markTestIncomplete(); |
| 326 | } |
| 327 | |
| 328 | $this->setup_http_hooks(); |
| 329 | add_filter( 'oembed_fetch_url', array( $this, 'filter_oembed_fetch_url' ), 99, 3 ); |
| 330 | |
| 331 | $invalid = '500" onmouseover="alert(document.cookie)'; |
| 332 | |
| 333 | $args = array( |
| 334 | 'width' => $invalid, |
| 335 | 'height' => $invalid, |
| 336 | ); |
| 337 | |
| 338 | // Only need to test with one URL for each provider |
| 339 | $url = $urls[0]; |
| 340 | |
| 341 | $msg = sprintf( "- Test URL: %s", $url ); |
| 342 | |
| 343 | $provider = self::$oembed->get_provider( $url, array( |
| 344 | 'discover' => false, |
| 345 | ) ); |
| 346 | $this->assertNotFalse( $provider, $msg ); |
| 347 | $data = self::$oembed->fetch( $provider, $url, $args ); |
| 348 | |
| 349 | $r = $this->http_response; |
| 350 | |
| 351 | $msg .= sprintf( "\n- oEmbed URL: %s", $r['url'] ); |
| 352 | |
| 353 | $query = parse_url( $r['url'], PHP_URL_QUERY ); |
| 354 | parse_str( $query, $query_vars ); |
| 355 | |
| 356 | // Test request |
| 357 | $this->assertInternalType( 'array', $query_vars, $msg ); |
| 358 | $this->assertArrayHasKey( 'maxheight', $query_vars, $msg ); |
| 359 | $this->assertArrayHasKey( 'maxwidth', $query_vars, $msg ); |
| 360 | $this->assertEquals( $args['width'], $query_vars['maxwidth'], $msg ); |
| 361 | $this->assertEquals( $args['height'], $query_vars['maxheight'], $msg ); |
| 362 | |
| 363 | // `WP_oEmbed::fetch()` only returns boolean false, so we need to hook into the HTTP API to get its error |
| 364 | if ( is_wp_error( $r['response'] ) ) { |
| 365 | $error_message = $r['response']->get_error_message(); |
| 366 | if ( empty( $error_message ) ) { |
| 367 | $error_message = '- no message -'; |
| 368 | } |
| 369 | |
| 370 | $this->fail( sprintf( "%s (%s)\n%s", $error_message, $r['response']->get_error_code(), $msg ) ); |
| 371 | } |
| 372 | |
| 373 | $this->assertTrue( in_array( wp_remote_retrieve_response_code( $r['response'] ), array( |
| 374 | 200, |
| 375 | 400, |
| 376 | 404, |
| 377 | ), true ), $msg ); |
| 378 | |
| 379 | if ( false === $data ) { |
| 380 | // For an erroneous request, it's valid to return no data (or no JSON/XML, which evaluates to false) and |
| 381 | // therefore the rest of the assertions can be skipped |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | // Check invalid data isn't echoed |
| 386 | $this->assertNotContains( 'onmouseover', wp_remote_retrieve_body( $r['response'] ), $msg ); |
| 387 | |
| 388 | if ( isset( $data->width ) ) { |
| 389 | $this->assertTrue( is_numeric( $data->width ), $msg ); |
| 390 | } |
| 391 | |
| 392 | if ( isset( $data->height ) ) { |
| 393 | $this->assertTrue( is_numeric( $data->height ), $msg ); |
| 394 | } |
| 395 | |
| 396 | if ( isset( $data->thumbnail_width ) ) { |
| 397 | $this->assertTrue( is_numeric( $data->thumbnail_width ), $msg ); |
| 398 | } |
| 399 | |
| 400 | if ( isset( $data->thumbnail_height ) ) { |
| 401 | $this->assertTrue( is_numeric( $data->thumbnail_height ), $msg ); |
| 402 | } |
| 403 | |
| 404 | remove_filter( 'oembed_fetch_url', array( $this, 'filter_oembed_fetch_url' ), 99 ); |
| 405 | $this->teardown_http_hooks(); |
| 406 | |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Test the tests |
| 411 | * |
| 412 | * @group oembed |
| 413 | * @ticket 32360 |
| 414 | */ |
| 415 | public function testOembedTestsCoverAllProviders() { |
| 416 | |
| 417 | $tests = wp_list_pluck( $this->oEmbedProviderData(), 0 ); |
| 418 | $providers = array_values( self::$provider_map ); |
| 419 | $missing = array_diff( $providers, $tests ); |
| 420 | |
| 421 | $this->assertEmpty( $missing, sprintf( "These oEmbed providers are not tested:\n- %s", implode( "\n- ", $missing ) ) ); |
| 422 | |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Test the tests |
| 427 | * |
| 428 | * @group oembed |
| 429 | * @ticket 32360 |
| 430 | * |
| 431 | */ |
| 432 | public function testOembedTestsAreAllUseful() { |
| 433 | |
| 434 | $tests = wp_list_pluck( $this->oEmbedProviderData(), 0 ); |
| 435 | $providers = array_keys( self::$oembed->providers ); |
| 436 | $useless = array_diff( $tests, $providers ); |
| 437 | |
| 438 | $this->assertEmpty( $useless, sprintf( "These tests do not cover any oEmbed provider:\n- %s", implode( "\n- ", $useless ) ) ); |
| 439 | |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Data provider for our oEmbed tests |
| 444 | * |
| 445 | * @return array |
| 446 | */ |
| 447 | public function oEmbedProviderData() { |
| 448 | $providers = self::$provider_map; |
| 449 | |
| 450 | return array( |
| 451 | // YouTube without www |
| 452 | array( |
| 453 | $providers['youtube'], |
| 454 | array( |
| 455 | 'http://youtube.com/watch?v=zdtD19tXX30', |
| 456 | 'http://m.youtube.com/watch?v=QkP_rOCBrpY', |
| 457 | ), |
| 458 | false, // HTTPS handled by different endpoints |
| 459 | ), |
| 460 | // YouTube with www |
| 461 | array( |
| 462 | $providers['youtube'], |
| 463 | array( |
| 464 | 'https://www.youtube.com/watch?v=bDRQRdFaFEo', |
| 465 | 'https://m.youtube.com/watch?v=yfUflij74P4', |
| 466 | ), |
| 467 | false, // HTTPS handled by different endpoints |
| 468 | ), |
| 469 | // YouTube Playlist without www |
| 470 | array( |
| 471 | $providers['youtube-playlist'], |
| 472 | array( |
| 473 | 'https://youtube.com/playlist?list=PL93B9F6B77FBB0160', |
| 474 | 'https://m.youtube.com/playlist?list=PL1AC02C68F976A10F', |
| 475 | ), |
| 476 | false, // HTTPS handled by different endpoints |
| 477 | ), |
| 478 | // YouTube Playlist with www |
| 479 | array( |
| 480 | $providers['youtube-playlist'], |
| 481 | array( |
| 482 | 'http://www.youtube.com/playlist?list=PLC7D2959C96B8D27B', |
| 483 | 'http://m.youtube.com/playlist?list=PLEC422D53B7588DC7', |
| 484 | ), |
| 485 | false, // HTTPS handled by different endpoints |
| 486 | ), |
| 487 | // YouTube HTTP Short Url |
| 488 | array( |
| 489 | $providers['youtube-shorturl'], |
| 490 | array( |
| 491 | 'http://youtu.be/nfWlot6h_JM?list=PLirAqAtl_h2r5g8xGajEwdXd3x1sZh8hC', |
| 492 | ), |
| 493 | false, // HTTPS handled by different endpoints |
| 494 | ), |
| 495 | // YouTube HTTPS Short Url |
| 496 | array( |
| 497 | $providers['youtube-shorturl'], |
| 498 | array( |
| 499 | 'https://youtu.be/U8SYRUYfs_I', |
| 500 | ), |
| 501 | false, // HTTPS handled by different endpoints |
| 502 | ), |
| 503 | array( |
| 504 | $providers['vimeo'], |
| 505 | array( |
| 506 | 'http://vimeo.com/12339198', |
| 507 | ), |
| 508 | true, |
| 509 | ), |
| 510 | array( |
| 511 | $providers['dailymotion'], |
| 512 | array( |
| 513 | 'http://www.dailymotion.com/video/x27bwvb_how-to-wake-up-better_news', |
| 514 | ), |
| 515 | true, |
| 516 | ), |
| 517 | array( |
| 518 | $providers['dailymotion-shorturl'], |
| 519 | array( |
| 520 | 'http://dai.ly/x33exze', |
| 521 | ), |
| 522 | false, // No HTTPS support |
| 523 | ), |
| 524 | array( |
| 525 | $providers['flickr'], |
| 526 | array( |
| 527 | 'http://www.flickr.com/photos/bon/14004280667/', |
| 528 | ), |
| 529 | true, |
| 530 | ), |
| 531 | array( |
| 532 | $providers['flickr-shorturl'], |
| 533 | array( |
| 534 | 'http://flic.kr/p/6BFrbQ', |
| 535 | ), |
| 536 | true, |
| 537 | ), |
| 538 | array( |
| 539 | $providers['smugmug'], |
| 540 | array( |
| 541 | 'http://fotoeffects.smugmug.com/Daily-shots-for-the-dailies/Dailies/6928550_9gMRmv/476011624_WhGWpts#!i=476011624&k=WhGWpts', |
| 542 | ), |
| 543 | true, |
| 544 | ), |
| 545 | array( |
| 546 | $providers['hulu'], |
| 547 | array( |
| 548 | 'http://www.hulu.com/watch/807443', |
| 549 | ), |
| 550 | true, |
| 551 | ), |
| 552 | array( |
| 553 | $providers['photobucket-album'], |
| 554 | array( |
| 555 | 'http://i415.photobucket.com/albums/pp236/Keefers_/Keffers%20Animals/funny-cats-a10.jpg', |
| 556 | ), |
| 557 | false, // No HTTPS support |
| 558 | ), |
| 559 | array( |
| 560 | $providers['photobucket-group'], |
| 561 | array( |
| 562 | // ?? |
| 563 | ), |
| 564 | false, // No HTTPS support |
| 565 | ), |
| 566 | array( |
| 567 | $providers['scribd'], |
| 568 | array( |
| 569 | 'http://www.scribd.com/doc/110799637/Synthesis-of-Knowledge-Effects-of-Fire-and-Thinning-Treatments-on-Understory-Vegetation-in-Dry-U-S-Forests', |
| 570 | ), |
| 571 | true, |
| 572 | ), |
| 573 | array( |
| 574 | $providers['wordpress-tv'], |
| 575 | array( |
| 576 | 'http://wordpress.tv/2015/08/18/billie/', |
| 577 | ), |
| 578 | true, |
| 579 | ), |
| 580 | array( |
| 581 | $providers['polldaddy'], |
| 582 | array( |
| 583 | 'http://polldaddy.com/poll/9066794/', |
| 584 | ), |
| 585 | true, |
| 586 | ), |
| 587 | array( |
| 588 | $providers['polldaddy-shorturl'], |
| 589 | array( |
| 590 | 'http://poll.fm/5ebze', |
| 591 | ), |
| 592 | false, // No HTTPS support |
| 593 | ), |
| 594 | array( |
| 595 | $providers['funnyordie'], |
| 596 | array( |
| 597 | 'http://www.funnyordie.com/videos/e5ef40bf2a/cute-overload', |
| 598 | ), |
| 599 | true, |
| 600 | ), |
| 601 | array( |
| 602 | $providers['twitter'], |
| 603 | array( |
| 604 | 'http://twitter.com/WordPress/status/633718182335922177', |
| 605 | ), |
| 606 | true, |
| 607 | ), |
| 608 | array( |
| 609 | $providers['twitter-timeline'], |
| 610 | array( |
| 611 | 'https://twitter.com/wordpress', |
| 612 | ), |
| 613 | true, |
| 614 | ), |
| 615 | array( |
| 616 | $providers['twitter-moment'], |
| 617 | array( |
| 618 | 'https://twitter.com/i/moments/770661957397573633', |
| 619 | ), |
| 620 | true, |
| 621 | ), |
| 622 | array( |
| 623 | $providers['reddit-comments'], |
| 624 | array( |
| 625 | 'https://www.reddit.com/r/Wordpress/comments/3xerq8/list_of_useful_wordpress_functions/' |
| 626 | ), |
| 627 | true, |
| 628 | ), |
| 629 | array( |
| 630 | $providers['vine'], |
| 631 | array( |
| 632 | 'http://vine.co/v/OjiLun5LuQ6', |
| 633 | ), |
| 634 | true, |
| 635 | ), |
| 636 | array( |
| 637 | $providers['soundcloud'], |
| 638 | array( |
| 639 | 'http://soundcloud.com/steveaoki/kid-cudi-pursuit-of-happiness', |
| 640 | ), |
| 641 | true, |
| 642 | ), |
| 643 | array( |
| 644 | $providers['slideshare'], |
| 645 | array( |
| 646 | 'http://www.slideshare.net/haraldf/business-quotes-for-2011', |
| 647 | ), |
| 648 | true, |
| 649 | ), |
| 650 | array( |
| 651 | $providers['instagram'], |
| 652 | array( |
| 653 | 'http://instagram.com/p/68WqXbTcfl/', |
| 654 | 'https://instagram.com/p/68WqXbTcfl/', |
| 655 | 'http://instagr.am/p/MRM3HQy6kh/', |
| 656 | ), |
| 657 | false, // No HTTPS support on instagr.am |
| 658 | ), |
| 659 | array( |
| 660 | $providers['spotify'], |
| 661 | array( |
| 662 | 'http://open.spotify.com/track/2i1KmyEXN3pNLwdxAWSGcg', |
| 663 | ), |
| 664 | true, |
| 665 | ), |
| 666 | array( |
| 667 | $providers['imgur'], |
| 668 | array( |
| 669 | 'http://imgur.com/a/WdJim', |
| 670 | 'http://i.imgur.com/mbOPX2L.png', |
| 671 | ), |
| 672 | true, |
| 673 | ), |
| 674 | array( |
| 675 | $providers['meetup'], |
| 676 | array( |
| 677 | 'http://www.meetup.com/WordPress-Amsterdam/events/224346396/', |
| 678 | 'http://meetu.ps/2L533w', |
| 679 | ), |
| 680 | true, |
| 681 | ), |
| 682 | array( |
| 683 | $providers['issuu'], |
| 684 | array( |
| 685 | 'http://issuu.com/vmagazine/docs/v87', |
| 686 | ), |
| 687 | true, |
| 688 | ), |
| 689 | array( |
| 690 | $providers['collegehumor'], |
| 691 | array( |
| 692 | 'http://www.collegehumor.com/video/2862877/jake-and-amir-math', |
| 693 | ), |
| 694 | true, |
| 695 | ), |
| 696 | array( |
| 697 | $providers['mixcloud'], |
| 698 | array( |
| 699 | 'http://www.mixcloud.com/8_8s/disclosurefriends/', |
| 700 | ), |
| 701 | true, |
| 702 | ), |
| 703 | array( |
| 704 | $providers['ted'], |
| 705 | array( |
| 706 | 'http://www.ted.com/talks/rodney_mullen_pop_an_ollie_and_innovate', |
| 707 | ), |
| 708 | true, |
| 709 | ), |
| 710 | array( |
| 711 | $providers['animoto'], |
| 712 | array( |
| 713 | 'http://animoto.com/play/MlRRgXHhoT8gOZyHanM6TA', |
| 714 | 'http://video214.com/play/MlRRgXHhoT8gOZyHanM6TA', |
| 715 | ), |
| 716 | true, |
| 717 | ), |
| 718 | array( |
| 719 | $providers['tumblr'], |
| 720 | array( |
| 721 | 'http://yahoo.tumblr.com/post/50902111638/tumblr-yahoo', |
| 722 | ), |
| 723 | false, // No HTTPS support |
| 724 | ), |
| 725 | array( |
| 726 | $providers['kickstarter'], |
| 727 | array( |
| 728 | 'http://www.kickstarter.com/projects/zackdangerbrown/potato-salad', |
| 729 | ), |
| 730 | true, |
| 731 | ), |
| 732 | array( |
| 733 | $providers['kickstarter-shorturl'], |
| 734 | array( |
| 735 | 'http://kck.st/1ukxHcx', |
| 736 | ), |
| 737 | false, // No HTTPS support |
| 738 | ), |
| 739 | array( |
| 740 | $providers['cloudup'], |
| 741 | array( |
| 742 | 'http://cloudup.com/cWX2Bi5DmfJ', |
| 743 | ), |
| 744 | true, |
| 745 | ), |
| 746 | array( |
| 747 | $providers['reverbnation'], |
| 748 | array( |
| 749 | 'http://www.reverbnation.com/enemyplanes/song/16729753-we-want-blood', |
| 750 | 'http://www.reverbnation.com/enemyplanes', |
| 751 | ), |
| 752 | true, |
| 753 | ), |
| 754 | array( |
| 755 | $providers['videopress'], |
| 756 | array( |
| 757 | 'https://videopress.com/v/kUJmAcSf', |
| 758 | ), |
| 759 | true, |
| 760 | ), |
| 761 | array( |
| 762 | $providers['speakerdeck'], |
| 763 | array( |
| 764 | 'https://speakerdeck.com/tollmanz/scaling-wordpress' |
| 765 | ), |
| 766 | true |
| 767 | ), |
| 768 | array( |
| 769 | $providers['facebook-post'], |
| 770 | array( |
| 771 | 'https://www.facebook.com/WordPress/posts/10154220015487911' |
| 772 | ), |
| 773 | true |
| 774 | ), |
| 775 | // array( |
| 776 | // $providers['facebook-activity'], |
| 777 | // array( |
| 778 | // '' |
| 779 | // ), |
| 780 | // true |
| 781 | // ), |
| 782 | array( |
| 783 | $providers['facebook-photo'], |
| 784 | array( |
| 785 | 'https://www.facebook.com/WordPress/photos/a.111006762910.97747.6427302910/10153207719422911/' |
| 786 | ), |
| 787 | true |
| 788 | ), |
| 789 | array( |
| 790 | $providers['facebook-permalink'], |
| 791 | array( |
| 792 | 'https://www.facebook.com/permalink.php?story_fbid=10154220015487911' |
| 793 | ), |
| 794 | true |
| 795 | ), |
| 796 | array( |
| 797 | $providers['facebook-media'], |
| 798 | array( |
| 799 | 'https://www.facebook.com/media/set/?set=a.164630483698579.1073741878.150601778434783&type=1&l=6c3a7725d5' |
| 800 | ), |
| 801 | true |
| 802 | ), |
| 803 | // array( |
| 804 | // $providers['facebook-questions'], |
| 805 | // array( |
| 806 | // '' |
| 807 | // ), |
| 808 | // true |
| 809 | // ), |
| 810 | array( |
| 811 | $providers['facebook-notes'], |
| 812 | array( |
| 813 | 'https://www.facebook.com/notes/facebook/searching-for-answers-ask-facebook-questions/411795942130/' |
| 814 | ), |
| 815 | true |
| 816 | ), |
| 817 | array( |
| 818 | $providers['facebook-video'], |
| 819 | array( |
| 820 | 'https://www.facebook.com/WordPress/videos/317622575398/' |
| 821 | ), |
| 822 | true |
| 823 | ), |
| 824 | array( |
| 825 | $providers['facebook-videophp'], |
| 826 | array( |
| 827 | 'https://www.facebook.com/video.php?v=317622575398', |
| 828 | 'https://www.facebook.com/video.php?id=317622575398', |
| 829 | ), |
| 830 | true |
| 831 | ), |
| 832 | ); |
| 833 | } |
| 834 | |
| 835 | protected function setup_http_hooks() { |
| 836 | add_action( 'http_api_debug', array( $this, 'action_http_api_debug' ), 99, 5 ); |
| 837 | } |
| 838 | |
| 839 | protected function teardown_http_hooks() { |
| 840 | remove_action( 'http_api_debug', array( $this, 'action_http_api_debug' ), 99 ); |
| 841 | $this->http_response = null; |
| 842 | } |
| 843 | |
| 844 | public function filter_oembed_fetch_url( $provider_url, $embed_url, $args ) { |
| 845 | // this allows us to test invalid data without it being converted to an integer in `WP_oEmbed::fetch()` |
| 846 | $provider_url = add_query_arg( 'maxwidth', $args['width'], $provider_url ); |
| 847 | $provider_url = add_query_arg( 'maxheight', $args['height'], $provider_url ); |
| 848 | return $provider_url; |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * Debugging action for the HTTP API response. |
| 853 | * |
| 854 | * @param array|WP_Error $response The HTTP response. |
| 855 | * @param string $action The debug action. |
| 856 | * @param string $class The HTTP transport class name. |
| 857 | * @param array $args HTTP request arguments. |
| 858 | * @param string $url The request URL. |
| 859 | */ |
| 860 | public function action_http_api_debug( $response, $action, $class, $args, $url ) { |
| 861 | |
| 862 | if ( 'response' !== $action ) { |
| 863 | return; |
| 864 | } |
| 865 | |
| 866 | $this->http_response = compact( 'response', 'args', 'url' ); |
| 867 | |
| 868 | } |
| 869 | |
| 870 | } |