Changeset 1359484
- Timestamp:
- 02/27/2016 10:29:44 AM (10 years ago)
- File:
-
- 1 edited
-
somatic-framework/trunk/inc/somaFunctions.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
somatic-framework/trunk/inc/somaFunctions.php
r875746 r1359484 1352 1352 } 1353 1353 1354 1354 1355 $media = array(); // init container 1355 1356 $width = $width ? $width : "853"; // iframe default … … 1361 1362 if (preg_match('%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) { 1362 1363 $id = $match[1]; 1363 $meta = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/videos/$id?v=2&alt=json"), true); // json_decode true returns data as array instead of object 1364 $meta = $meta['entry']; // isolate the single entry we requested 1364 ob_start(); 1365 ini_set('user_agent','Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17'); 1366 // $meta = file_get_contents("http://gdata.youtube.com/feeds/api/videos/".$id."?v=2&alt=json"); // old, don't work?? 1367 $meta = file_get_contents("https://www.youtube.com/oembed?url=".$url."&format=json"); 1368 $meta = json_decode($meta, true); // json_decode true returns data as array instead of object 1369 ob_end_clean(); 1370 1365 1371 $media['url'] = "http://www.youtube.com/watch?v=$id"; // rebuild external url 1366 1372 $media['id'] = $id; 1367 1373 $media['site'] = $site; 1368 $media['thumb'] = $meta[' media$group']['media$thumbnail'][1]['url']; // grabs url of medium 360x480 image1369 $media['title'] = stripslashes($meta['media$group']['media$title']['$t']);1370 $media['desc'] = stripslashes($meta['media$group']['media$description']['$t']);1371 $media['duration'] = $meta['media$group']['media$content'][0]['duration'];1374 $media['thumb'] = $meta['thumbnail_url']; // grabs url of medium 360x480 image 1375 $media['title'] = $meta['title']; 1376 // $media['desc'] = stripslashes($meta['media$group']['media$description']['$t']); 1377 // $media['duration'] = $meta['media$group']['media$content'][0]['duration']; 1372 1378 $media['mobile'] = "youtube:$id"; // launches youtube app, i think... 1373 1379 $media['embed'] = "<iframe width=\"$width\" height=\"$height\" src=\"http://www.youtube.com/embed/$id?rel=0&hd=1\" frameborder=\"0\" allowfullscreen></iframe>"; 1374 1380 $media['iframe'] = "http://www.youtube.com/embed/$id?rel=0&hd=1&autoplay=1"; // url to pass to iframe renderers 1375 $media['api'] = $meta; // we include everything we got from the site API, just in case (each site formats differently)1381 // $media['api'] = $meta; // we include everything we got from the site API, just in case (each site formats differently) 1376 1382 } else { 1377 1383 return new WP_Error('missing', "Can't extract ID from youtube URL..."); … … 1379 1385 break; 1380 1386 case "vimeo"; 1381 if ($oembed = json_decode(file_get_contents("http://vimeo.com/api/oembed.json?url=".urlencode($url)), true)) { // get oembed metadata 1387 // try to get around 403 forbidden errors when using file_get_contents 1388 ob_start(); 1389 ini_set('user_agent','Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17'); 1390 $oembed = file_get_contents("https://vimeo.com/api/oembed.json?url=".urlencode($url)); 1391 $oembed = json_decode($oembed, true); 1392 ob_end_clean(); 1393 if (!empty($oembed)) { // get oembed metadata 1382 1394 $id = $oembed['video_id']; // extract id from api response 1383 $meta = array_shift(unserialize(file_get_contents("http://vimeo.com/api/v2/video/$id.php"))); // get more metadata (note: we're making two distinct calls to API for vimeo) 1395 ob_start(); 1396 ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)'); 1397 $meta = file_get_contents("https://vimeo.com/api/v2/video/$id.php"); 1398 ob_end_clean(); 1399 $meta = array_shift(unserialize($meta)); // get more metadata (note: we're making two distinct calls to API for vimeo) 1384 1400 $meta = array_merge($oembed, $meta); // combine the two (including some overlapping keys) 1385 1401 $media['url'] = "http://vimeo.com/$id"; // rebuild external url
Note: See TracChangeset
for help on using the changeset viewer.