I just set up a WP blog and installed JW player to manage YouTube video's on the blog. But with 1AND1 hosting the allow_url_fopen is disabled and I couldn't enable it for soom reason with local php.ini files, so I figured I would replace the simpleXML load with cURL. This also provides better security accoriding to phpsec.com.
So in order to get YouTube videos to import in WordPress using cURL we need to add about 5 lines of code to the jw-player-plugin-for-wordpress/media/JWURLImportManager.php which can be edited right in WordPress. Just go to the plugins page in the admin control panel and click edit on the JW Player plugin. Look for the JWURLImportManager.php file and scroll to the bottom. This is what the code will look like.
Code:
//**
* In the case of a YouTube URL this function retrieves the relevant metadata
* from the YouTube API.
* @param string $video_id The YouTube video id.
* @return array The array of relevant YouTube metadata.
*/
function get_youtube_meta_data($video_id = "") {
if ($video_id == "") {
return "";
}
$youtube_meta = array();
$youtube_url = "http://gdata.youtube.com/feeds/api/videos/" . $video_id;
$youtube_xml = simplexml_load_file($youtube_url);
$youtube_meta["author"] = (string) $youtube_xml->author->name;
$youtube_media = $youtube_xml->children("http://search.yahoo.com/mrss/");
$youtube_meta["title"] = $youtube_media->group->title;
$youtube_meta["description"] = $youtube_media->group->description;
$thumbnails = $youtube_xml->xpath("media:group/media:thumbnail");
foreach ($thumbnails as $thumbnail) {
if ($thumbnail["height"] == 240) {
$youtube_meta["thumbnail_url"] = (string) $thumbnail["url"];
break;
}
}
return $youtube_meta;
}
?>
Now replace that block of code with this one.
Code:
/**
* In the case of a YouTube URL this function retrieves the relevant metadata
* from the YouTube API.
* @param string $video_id The YouTube video id.
* @return array The array of relevant YouTube metadata.
*/
function get_youtube_meta_data($video_id = "") {
if ($video_id == "") {
return "";
}
$youtube_meta = array();
$youtube_url = "http://gdata.youtube.com/feeds/api/videos/" . $video_id;
$youtube_curl = curl_init($youtube_url);
curl_setopt($youtube_curl, CURLOPT_HEADER, false);
curl_setopt($youtube_curl, CURLOPT_RETURNTRANSFER, true);
$youtube_raw = curl_exec($youtube_curl);
curl_close($youtube_curl);
$youtube_xml = simplexml_load_string($youtube_raw);
$youtube_meta["author"] = (string) $youtube_xml->author->name;
$youtube_media = $youtube_xml->children("http://search.yahoo.com/mrss/");
$youtube_meta["title"] = $youtube_media->group->title;
$youtube_meta["description"] = $youtube_media->group->description;
$thumbnails = $youtube_xml->xpath("media:group/media:thumbnail");
foreach ($thumbnails as $thumbnail) {
if ($thumbnail["height"] == 240) {
$youtube_meta["thumbnail_url"] = (string) $thumbnail["url"];
break;
}
}
return $youtube_meta;
}
?>
Now save changes and try to load a YouTube video into a post and I have more[/FONT] information at Using cURL with JW Player Plugin for Wordpress at my blog.
__________________
Please login or register to view this content. Registration is FREE
Fav sites; last.fm, mashable.com, speckyboy.com
Last edited by captkrackerjack; 10-15-2010 at 11:28 AM..
Reason: Fixed gramar errors.
|