Template:Random Popular Videos Code

From OpenSocial Directory

Jump to: navigation, search
  <?xml version="1.0" encoding="UTF-8" ?> 
  <Module>
  <ModulePrefs title="Random Popular Videos" title_url="http://www.ulinkx.com/" description="Popular videos from the Youtube, Google, Metacafe, MySpace, Dailymotion, Revver etc. served randomly." height="350" screenshot="http://www.ulinkx.com/images/random_popular_videos.png" author="uLinkx, Inc." author_affiliation="None" author_email="admin@ulinkx.com" author_location="California,USA">
  <Require feature="opensocial-0.5" /> 
  <Require feature="analytics" /> 
  <Require feature="dynamic-height" /> 
  </ModulePrefs>
  <Content type="html">
  <![CDATA[ 
<div id="random_videos">
</div>

<script type="text/javascript">

var is_opensocial = 1;
var surface="profile";
var autoplay = 0;
var viewer_id = "0";
var viewer_friends_list = "";
var autoplay = 0; // Don't play for the first time
var base_url = 'http://www.ulinkx.com/opensocial/';

function getViewerId()
{
	return viewer_id;
}

function getViewerFriends()
{
	return viewer_friends_list;
}

function getContainer()
{
   if (document.location.toString().match(/orkut/) )
   {
	  return "orkut";
   }
   else if (document.location.toString().match(/ning/) )
   {
	  return "ning";
   }
   else if (document.location.toString().match(/hi5/) )
   {
	  return "hi5";
   }
   else if (document.location.toString().match(/plaxo/) )
   {
	  return "plaxo";
   }
   else if (document.location.toString().match(/bebo/) )
   {
	  return "bebo";
   }
   else
   {
	  return "unknown";
   }
}	

function getSurface()
{
	return document.location.toString().match(/mode=canvas/) ? "canvas" : "profile";
}

function getSurfaceMode()
{
	return is_opensocial ? getSurface(): surface;
}

function manageFavoriteResponse(response)
{
  _gel("ilikeit").innerHTML = response;
}

function manageFavorites( video_id, add )
{
  var url = base_url;
  if ( parseInt(add) == 1 )
    url += "addfav?";
  else
    url += "deletefav?";

  url += "surface=" + getSurfaceMode();
  url += "&viewer_id=" + getViewerId();
  url += "&container=" + getContainer();
  url += "&video_id=" + video_id;
  _IG_FetchContent(url, manageFavoriteResponse, { refreshInterval: 0 });
}

function getFavoriteResponse(response)
{
  _gel("fav_videos").innerHTML = response;
  _IG_AdjustIFrameHeight();
}

function getFavorites( video_id, is_friends )
{
  var url = base_url;
  if (parseInt(is_friends) == 0 ) 
	url += "getfav?";
  else
	url += "getfriendsfav?";

  url += "surface=" + getSurfaceMode();
  url += "&friends=" + getViewerFriends();
  url += "&viewer_id=" + getViewerId();
  url += "&container=" + getContainer();
  url += "&video_id=" + video_id;
  _IG_FetchContent(url, getFavoriteResponse, { refreshInterval: 0 });
}

function playVideoResponse(response)
{
  _gel("video_player").innerHTML = response;
  _IG_AdjustIFrameHeight();
}

function playVideo( video_id )
{
  var url = base_url + "playvideo?" + "surface=" + getSurfaceMode();
  url += "&viewer_id=" + getViewerId();
  url += "&container=" + getContainer();
  url += "&video_id=" + video_id;
  _IG_FetchContent(url, playVideoResponse, { getPlayResponse: 0 });
}

function getNextVideoResponse(response)
{
  html = response;

  _gel("video_player").innerHTML = html;
  _IG_AdjustIFrameHeight();
}

function getNextVideo()
{
  var url = base_url + "nextvideo?" + "surface=" + getSurfaceMode();
  url += "&viewer_id=" + getViewerId();
  url += "&friends=" + getViewerFriends();
  url += "&container=" + getContainer();
  url += "&width=" + window.innerWidth;
  url += "&height=" + window.innerHeight;
  url += "&autoplay=" + autoplay;
  _IG_FetchContent(url, getNextVideoResponse, { refreshInterval: 0 });
}

function getRandomVideoResponse(response)
{
  html = response;

  _gel("random_videos").innerHTML = html;
  _IG_AdjustIFrameHeight();
  _IG_Analytics("UA-345781-1", "/gadget/random_popular_videos");
}

function getRandomVideo()
{
  var url = base_url + "randomvideo?" + "surface=" + getSurfaceMode();
  url += "&viewer_id=" + getViewerId();
  url += "&friends=" + getViewerFriends();
  url += "&container=" + getContainer();
  url += "&width=" + window.innerWidth;
  url += "&height=" + window.innerHeight;
  url += "&autoplay=" + autoplay;
  autoplay = 1
  _IG_FetchContent(url, getRandomVideoResponse, { refreshInterval: 0 });
}

function response(data) {
  var viewer = data.get("viewer").getData();
  viewer_id = viewer.getId();
  
  var viewer_friends = data.get("viewer_friends").getData();
  viewer_friends.each(function(person) {
	viewer_friends_list += person.getId() + ",";
  });
  
  getRandomVideo();
} 

function viewerRequest() 
{
  var req = opensocial.newDataRequest();
  req.add(req.newFetchPersonRequest("VIEWER"), "viewer");
  req.add(req.newFetchPeopleRequest("VIEWER_FRIENDS"), "viewer_friends");
  req.send(response);
}

function loadFirstVideo()
{
	viewerRequest();
}

_IG_RegisterOnloadHandler( loadFirstVideo() );

</script>



  ]]> 
  </Content>
  </Module>
Personal tools
communication