function socialfeed_youtube in Social Feed 6
Retrieves Data from Youtube.
2 calls to socialfeed_youtube()
- socialfeed_cron in ./
socialfeed.module - Implements hook_cron().
- socialfeed_settings_form_submit in ./
socialfeed.module - Implements form_submit().
File
- ./
socialfeed.module, line 485 - Module for fetching data from Facebook, Twitter, Youtube, and Foursquare. This module provides block content retrieved from a
Code
function socialfeed_youtube() {
$youtubeprofile = variable_get('socialfeed_youtube_profile_name', FALSE);
$feedurl = drupal_http_request("http://gdata.youtube.com/feeds/api/users/{$youtubeprofile}/uploads?format=5", array(), 'GET', NULL, 1);
if ($feedurl->status_message == 'OK') {
libxml_use_internal_errors(TRUE);
try {
$sxml = new SimpleXMLElement($feedurl->data);
} catch (Exception $e) {
// Retreat!
return;
}
/**
* Inserts Youtube Data.
*/
function socialfeed_youtube_insert($table, $data) {
// Retrieve this early for the check query.
$arr = explode('/', $data->id);
$id = $arr[count($arr) - 1];
$query = "SELECT * FROM {socialfeed_post} WHERE id = '%s'";
$sql = db_query_range($query, $id, 0, 1);
while ($item = db_fetch_object($sql)) {
$myterms[] = $item;
}
if (!$myterms) {
$media = $data
->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->player
->attributes();
$watch = $attrs['url'];
$attrs = $media->group->thumbnail[0]
->attributes();
$thumbnail = $attrs['url'];
$post = array();
$post['time'] = strtotime($data->published);
$post['message'] = $media->group->description;
$post['picture'] = $thumbnail;
$post['link'] = $watch;
$post['title'] = $media->group->title;
$post['id'] = $id;
$post['post_type'] = 'youtube';
$post['name'] = $data->author->name;
drupal_write_record('socialfeed_post', $post);
}
}
if ($sxml->entry) {
foreach ($sxml->entry as $object) {
socialfeed_youtube_insert("socialfeed_post", $object);
}
}
}
}