Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Feb 4, 2011 22:51:13 GMT -8
Browser tested: This code belongs in MAIN FOOTER and was written with Firefox, but IE and Chrome seem to like it too. It was created from a request on PBS but ran into a roadblock when it was discovered Proboards never created a chat stream with their gigya account or just doesn't wish to make it public. Without the chat stream ID all the code does is show your online friends in the info center, no way to click and actually talk to them. Seems quite a shame to waste it so I'll post it here. The Gigya API is also capable of filtering the friends list to show who is actually logged in on the forum so I supposed a click could be made to open PM for those that are logged in but that seems redundant. The other option of starting the messaging client associated with that network might work too but only for networks that support a custom protocol such as aim or live. Anywho, without further ado, here's the code <script> (function(){ if(arguments[0]==false)return; var soE={ noNet:"Please use the Gigya social network selector to login to a network first", noFriends:"no friends are currently available", noFriendCapable:"Please use the Gigya social network selector to login to a network that supports friends", noNotificationCapable:"This friend cannot receive notifications" } var cv = {show:"show.png",hide:"hide.png"}; if(!window.console)window.console={log:function(){}}; var a,b=document.getElementsByTagName('tr'),c,d,e,re=/changevisibility&(amp;)?type=today/ var Gss=gigya.services.socialize; window.showFriends = function(response){ console.log((response.operation||response.eventName)+': %o',response); var friends = document.getElementById('socialFriends'), operation = (response.operation||response.eventName); if (!response.errorCode || response.errorCode == 0) { if(response.user)showFriends.sendNotification.user=response.user; if(operation=="connectionRemoved" && !response.user.isConnected){friends.innerHTML=soE.noNet; friends.previousSibling.innerHTML="";return;} Gss.getFriendsInfo(conf,{ callback:function(res){ console.log(res.operation+': %o',res); if(res.errorCode==0){ var myFriends = res['friends'].asArray(),msg="",providers={},index,index2,currFriend; if ( null!=myFriends && myFriends.length>0) { showFriends.sendNotification.friends = res.friends; for(index in myFriends) { currFriend = myFriends[index]; for(index2 in currFriend.identities){ if(!providers[index2+' friend'])providers[index2+' friend']=1; else providers[index2+' friend']++; var status = '<img style="position: relative; z-index: 205; top: -1px; left: -12px;" src="http://socialize.gigya.com/gs/i/comments/providers/'+index2+'User_14x14.gif">'; } msg += '<div style="display:inline-block;padding-left:2px;float:left;" align="center" uid="'+currFriend.UID+'" onclick="showFriends.sendNotification(this)"><img src="'+ currFriend['thumbnailURL']+ '" title="'+index2+'" onerror="this.src=\'http://read-write.appspot.com/images/nopic.gif\'">'+status+'<br>'+currFriend['nickname']+'</div>'; } if(friends.innerHTML!="hidden")friends.innerHTML=msg; msg=[""]; for(index in providers)msg.push(providers[index]+' '+index+(providers[index]>1?'s':'')); friends.previousSibling.innerHTML=(msg.join(", ")+"<br><br>").replace(/^,/,''); } else {if(friends.innerHTML!="hidden")friends.innerHTML=soE.noFriends;friends.previousSibling.innerHTML="";} }else friends.innerHTML='Error('+res.operation+') :' + res.errorMessage; } });
} else friends.innerHTML = 'Error('+response.operation+') :' + response.errorMessage; } showFriends.sendNotification = function(friend){ if(!friend || !friend.getAttribute("uid")){console.log(friend);return false;} var ac=arguments.callee,friendObj,index; if(ac.user.capabilities.notifications){ for(index in ac.friends)if(ac.friends[index].UID==friend.getAttribute('uid')){friendObj=ac.friends[index];break} if(friendObj && !friendObj.capabilities.notifications){ alert(soE.noNotificationCapable);return } ac.UIDS=[friend.getAttribute('uid')]; alert(friend.getAttribute('uid')) }else alert('not currently connected to a network that allows notifications'); } Gss.addEventHandlers(conf,{onConnectionAdded:showFriends}); Gss.addEventHandlers(conf,{onConnectionRemoved:showFriends}); for(a=b.length-1;a>=0;a--){ if(b[a].firstChild && /\bcatbg\b/.test(b[a].firstChild.className) && re.test(b[a].firstChild.innerHTML)){ c=b[a]; d=c.cloneNode(-1); d.getElementsByTagName('b')[0].innerHTML='Social Networking Friends'; e = d.getElementsByTagName('a'); e=e[e.length-1]; e.href="javascript:void('hide friends')"; e.lastChild.onclick = function(){ var T=this,src=T.src; if(T.src.match(cv.hide)){ src = src.replace(cv.hide,cv.show); document.getElementById('socialFriends').innerHTML = "hidden" }else{ src = src.replace(cv.show,cv.hide); document.getElementById('socialFriends').innerHTML = ""; } document.cookie = "socialFriends="+escape(src)+";expires="+(new Date(+new Date + 1e11)).toGMTString()+";"; setTimeout(function(){T.src=src;},5); showFriends({errorCode:0,operation:'manualCallback'}); } e.lastChild.onload= function(){ var display = document.cookie.match(/socialFriends=([^;]+)/)?unescape(RegExp.$1):"",hide= new RegExp(cv.hide,"i"); if(display.length>0){ if(!hide.test(display))document.getElementById('socialFriends').innerHTML = "hidden"; if(display!=this.src)this.src=display; } } c.parentNode.appendChild(d); e=c.nextSibling.cloneNode(-1); c.parentNode.appendChild(e); d=e.lastChild.getElementsByTagName('font')[0]; d.innerHTML=soE.noFriends; d.id="socialFriends"; d.parentNode.insertBefore(document.createElement('div'),d); d.previousSibling.id="addNetwork"; d.previousSibling.style.cssFloat= d.previousSibling.style.styleFloat= "right"; d.parentNode.insertBefore(document.createElement('div'),d); Gss.showAddConnectionsUI(conf, { containerID:'addNetwork' ,showEditLink:true ,showTermsLink:false ,requiredCapabilities:'friends' ,cid:pb_forum+"."+pb_username+".onlinefriends" }); Gss.getUserInfo(conf,{callback:function(res){ console.log(res.operation+': %o',res); var friends = document.getElementById('socialFriends'); if(res.errorCode==0){ if(!res.user || !res.user.isConnected){friends.innerHTML=soE.noNet; friends.previousSibling.innerHTML="";return;} showFriends.sendNotification.user = res.user; if(res.user.capabilities.friends) showFriends({errorCode:0,operation:'manualCallback'}); else {friends.innerHTML= res.user.isConnected?soE.noFriendsCapable:soE.noNet; friends.previousSibling.innerHTML="";} }else document.getElementById('socialFriends').innerHTML= 'Error('+res.operation+') :' + res.errorMessage; } }); break; } } })(pb_action=="home" && pb_username!='Guest') </script> Notes:- The code only knows the standard InfoCenter so if using a remodel then this code should run before the remodel occurs.
- Most networks define "friend" as someone who is not only in your list but they also have you in theirs. In the case of twitter a "friend" is someone you are following and who is also following you. In addition, some networks such as yahoo and live, require an acceptance by both parties before linking them as them friends.
- You must actively log into the network in order to see friends from that network. The network login control created on the right of the new info center section allows you to see at a glance which of the networks supported by Proboards login has you logged in as well as allow you to selectively login/logout of any of the networks.
- Logging in using Proboards social login is useless (for this code) since Proboards automatically logs you out once logged into the forum. You'll need to use the social login in the info center
|
|
|
Post by Wormopolis on Feb 13, 2011 23:18:13 GMT -8
having in my info center currently (and it worked with remodel).
facebook shows everyone.. but Yahoo doesnt seem to show anyone.. even when I can see they are online.
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Feb 15, 2011 22:42:15 GMT -8
It's really a not-ready-for-prime-time script. Until I can figure out the next logical step (chat stream) to make the code actually useful it is merely a proof-of-concept and can be considered eye candy.
|
|