Home About Us Developer Blogs JomSocial The Right way to fetch media in JomSocial - Developer Blog
The Right way to fetch media in JomSocial - Developer Blog
Friday, 07 January 2011 15:07

While doing some R & D work while working on J!MailAlert plugins, we realized that majority of extensions were not using the right way..This resulted in broken image links especially when using Amazon S3. So here's some easy to use code snippets to fetch JomSocial Photo thumbnails, Video thumbnails, Group Avatar thumbnails etc..This is missing in the JomSocial Docs.. hence this blog..

Hope you find them useful.

/*TO GET THUMBNAILS FOR JOMSOCIAL PHOTOS*/
//first get photo ids from local database
$query="SELECT a.id, a.thumbnail FROM jos_community_photos AS a”;
$db->setQuery($query);
$row = $db->loadObjectList();
//JS API - this is used or getting thumbnails for JS photos
CFactory::load( 'models' , 'photos' );
$photo =& JTable::getInstance( 'Photo' , 'CTable' );
if(!empty($row))
{
foreach($row as $data)
{
$photo->load( $data->id );
$thumbnail = $photo->getThumbURI();
$data->thumbnail=$thumbnail;
}
}
//now $row will be having thumnails from local OR amazon s3 whatever applicable
/*TO GET THUMBNAILS FOR JOMSOCIAL VIDEOES*/
//first get video ids from local database
$query = "SELECT v.id,v.thumb FROM #__community_videos as v”;
$db->setQuery($query);
$video_result = $db->loadObjectList();
//JS API - this is used for getting thumbnails for JS videos
CFactory::load('models' , 'videos');
$video =& JTable::getInstance( 'Video' , 'CTable' );
if(!empty($video_result))
{
foreach($video_result as $data)
{
if(($video->load($data->id)) && ($data->thumb)){
$data->thumb=$video->getThumbnail();
}
else{
$data->thumb=JURI::root().'components'.DS.'com_community'.DS.'assets'.DS.'video_thumb.png';
}
}
}
//now $video_result will be having video thumnails from local OR amazon s3 whatever applicable
/*TO GET GROUP-AVATAR FOR JOMSOCIAL GROUPS*/
//suppose you want to get a group avatar thumbnail for a group having groupid=3
//then use following code
$gid=3;
CFactory::load( 'models' , 'groups' );
$group=& JTable::getInstance( 'Group' , 'CTable' );
$group->load( $gid);
$avatar_img_source=$group->getThumbAvatar('avatar');
//now $avatar_img_source will be having the image source for group avatar thumbnail
/*TO GET USER-AVATAR FOR JOMSOCIAL USER*/
//suppose you want to get a user avatar thumbnail for a user having userid=63
//then use following code
$userid=63;
$user=&CFactory::getUser($userid);
$uimage = $user->getThumbAvatar();
//now $uimage will be having the image source for user avatar thumbnail

blog comments powered by Disqus
 

Smartphone Applications

Newsletter Signup

Jump on to our Newsletter & stay updated on News on our Extensions, New Releases & Offers !