Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using cURL with JW Player Plugin for WordPress.
Old 10-14-2010, 09:55 AM Using cURL with JW Player Plugin for WordPress.
captkrackerjack's Avatar
Experienced Talker

Latest Blog Post:
Moved Blog to NGINX!
Posts: 31
Name: Greg
Location: California
Trades: 0
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.
captkrackerjack is offline
Reply With Quote
View Public Profile Visit captkrackerjack's homepage!
 
 
Register now for full access!
Reply     « Reply to Using cURL with JW Player Plugin for WordPress.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13752 seconds with 12 queries