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