0) $spanrow--; else $spanrow=2;
if ($limit<=0) $limit=6;
switch ($type) {
//The latest videos from a channel or only the videos that match your keywords
case "uploads":
$feedURL=tubematic_composeurl("http://gdata.youtube.com/feeds/api/users/$q/uploads",$limit,$orderby,$lr);
/*
use this parameter to create a filter for a feed. Obtain only the videos that contain your query in the metadata (title, tags, description).
*/
if (!empty($keys)) $feedURL.="&q=$keys";
break;
// Search in a category
case "category":
$feedURL = tubematic_composeurl("http://gdata.youtube.com/feeds/api/videos/-/{$q}",$limit,$orderby,$lr);
break;
// Search feeds
case "searchfeed":
$feedURL = tubematic_composeurl("http://gdata.youtube.com/feeds/api/videos",$limit,$orderby,$lr);
/*
use this parameter to create a filter for a feed. Obtain only the videos that contain your query in the metadata (title, tags, description).
*/
if (!empty($keys)) $feedURL.="&q=$keys";
break;
default:
$feedURL="";
break;
}
if (empty($feedURL)) return ""; // nothing to do
// read feed into SimpleXML object
$sxml = @simplexml_load_file($feedURL);
//echo $sxml->title;
//iterate over entries in feed
$span=0;
$vg.="
";
if (!$sxml) return ""; // uhm.. something was bad
foreach ($sxml->entry as $entry) {
// get date
$published=$entry->published;
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
// get node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
// get node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
//if (!in_array($orderby,array("published","updated"))) $viewCount = $attrs->viewCount;
//else $showcount=false;
$viewCount = @$attrs->viewCount;
if (!$viewCount) $showcount=false;
// get node for video ratings
/*$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}*/
if ($span==0) $vg.="";
$vg .= '
';
$vg.=' | ';
if($showtitle){$vg.=''.$media->group->title.' | ';}
if($showuser){$vg.=''.$tm_by_label.''.$entry->author->name.' | ';}
if($showdate){$vg.=''.strftime($tm_datetime_filer,strtotime($published)).' | ';}
if($showcount){$vg.=''.$tm_views_label.$viewCount.' | ';}
$vg.=''.$tm_duration_label.$length.'s | ';
$vg.=' |
';
if ($span==$spanrow) { $vg.=" |
"; $span=0; }
else $span++;
}
$vg.="
";
return $vg;
}
function tubematic_composeurl($feedURL,$limit,$orderby,$lr='') {
/*
orderby={updated, viewCount, rating, relevance}: sort the items from feed by upload date, number of views, rating or relevance
*/
if (!in_array($orderby,array("updated","rating","relevance","published"))) $orderby="viewCount";
$feedURL.="?orderby=$orderby";
/*
the maximum number of items from a feed (by default, a feed includes only 25 items)
*/
$feedURL.="&max-results=$limit";
/*
the lr parameter restricts the search to videos that have a title, description or keywords in a specific language. Valid values for the lr parameter are ISO 639-1 two-letter language codes. You can also use the values zh-Hans for simplified Chinese and zh-Hant for traditional Chinese.
*/
if (!empty($lr)) $feedURL.="&lr=$lr";
return $feedURL;
}
add_shortcode('tubematic', 'shortcode_tubematic');
?>